+ Reply to Thread
Results 1 to 5 of 5

Runtime error 1004 while loading Add-In

Hybrid View

  1. #1
    Registered User
    Join Date
    07-04-2009
    Location
    San Diego
    MS-Off Ver
    CA
    Posts
    4

    Runtime error 1004 while loading Add-In

    Hello:

    I have a workopen event as follows:
    Private Sub Workbook_Open()
    	Application.MacroOptions Macro:="Fintest1", _
            Description:="Square", _
            Category:=14, _
            HelpContextID:=25, _
      HelpFile:=ThisWorkbook.Path & "\FinPak3test.chm"
    
    End Sub
    The workbook is saved as an xlam file.

    If I open this file after Excel 2007 loads with file open menu
    everything is fine. The code runs without error and
    the helpcontext etc work just fine.

    Now if I load the file as an add-in through the add-in
    manger using the Excel Option menu it again works just fine.

    But if I close Excel and then Open Excel (so that add-in
    loads automatically) I get an error message that says:
    Run-time error '1004'
    Cannot edit a macro on a hidden workbook. Unhide
    the working using the Unhide command.
    Can someone help so that the code works when
    add-in is loaded automatically?

    Thanks.
    Last edited by PVBERG; 07-07-2009 at 01:01 PM. Reason: Added Code and Quote Tags

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Runtime error 1004 while loading Add-In

    How about placing the code in a routine within a standard code module and calling that using the OnTime method

    Thisworkbook object
    Private Sub Workbook_Open()
        
        Application.OnTime Now + TimeValue("00:00:00"), "AssignHelp"
    
    End Sub
    Standard code module
    Public Sub AssignHelp()
        
        Application.MacroOptions Macro:="Fintest1", _
            Description:="Square", _
            Category:=14, _
            HelpContextID:=25, _
            HelpFile:=ThisWorkbook.Path & "\FinPak3test.chm"
    
        MsgBox "Assigned"  ' for testing only
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    07-04-2009
    Location
    San Diego
    MS-Off Ver
    CA
    Posts
    4

    Re: Runtime error 1004 while loading Add-In

    Hello Andy:

    Thank you so much for your suggestion. It solved the problem.

    If you are willing could you explain what the difference is between
    the method you suggested and a plain call to the routine such as
    Call AssignedHelp? (I first did it this way and it did not work. I posted
    the code I did because it was more direct.) Particularly since
    the time you added to "now" is apparently zero. I guess
    I would be less confused if you had suggested that I add
    a small amount of time to delay the call.

    Again thanks for your help

    Pieter

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Runtime error 1004 while loading Add-In

    apparently the small delay in processing the command via the ONTIME rather than a direct Call allows excel to untwist it's knickers.

  5. #5
    Registered User
    Join Date
    07-04-2009
    Location
    San Diego
    MS-Off Ver
    CA
    Posts
    4

    Re: Runtime error 1004 while loading Add-In

    Hello:

    Thanks again for the information. I have played with it a little more and I think you are right. I have tried loading Excel a number of times and there were a few times that I still got the error, so it may just depend on what else is going on. So to make sure I have added a slight amount of time to the NOW to insure that even if it processes very quickly there will be a sufficient delay. I have not had a failure since.


    Pieter

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1