+ Reply to Thread
Results 1 to 4 of 4

Macro Runs in Debug Mode but give run-time error 1004 when called from control object

  1. #1
    Registered User
    Join Date
    02-23-2011
    Location
    Inactive Profile
    MS-Off Ver
    Inactive Profile
    Posts
    11

    Macro Runs in Debug Mode but give run-time error 1004 when called from control object

    I am using macros to update the links in my current workbook to other closed workbooks.

    I have used the same code twice for links in 2 different workbooks:

    ActiveWorkbook.UpdateLink Name:= _
    "U:\Finance\Reporting\Dailies\Data\<file name>.xlsx", Type:=xlExcelLinks

    The UpdateLink code for each file is in an independent macro
    I have another "master" macro which calls each of these 2 macros as well as a couple other macros in the workbook.
    I have a control object ("button") in the sheet to which this "master" macro is assigned.

    ~ Both UpdateLink macros run perfectly if I run them independently from Excel (ie: Developer, Macros, Macro Name, Run)
    ~ The "master" macro which combines the 2 UpdateLink macros runs perfectly in debug mode.
    ~ When I run the "master" macro from the control object in my worksheet, I get the following error:
    Run-time error '1004': Method of 'UpdateLink' of object '_Workbook' failed

    ~ After rem'ing out each of the UpdateLink macros from the "master" macro, I have determined that one of the updates works fine and the other is the problem. I have also determined that it does not matter which order I call them in, the same Updatelink macro always causes the error.

    Since they run independently and they run combined in debug mode, I'm at a loss as to what is causing the error or how to fix it. Help!!!

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Macro Runs in Debug Mode but give run-time error 1004 when called from control object

    Can you provide the whole procedure?
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    02-23-2011
    Location
    Inactive Profile
    MS-Off Ver
    Inactive Profile
    Posts
    11

    Re: Macro Runs in Debug Mode but give run-time error 1004 when called from control object

    Quote Originally Posted by Mordred View Post
    Can you provide the whole procedure?

    It is very simplistic stuff:


    Sub FreezeYesday()
    '
    '
    Sheets("TdayYesday").Visible = True
    Application.Goto Reference:="Today"
    Selection.Copy
    Application.Goto Reference:="Yesday"
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("TdayYesday").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Summary").Select
    Range("A1").Select
    End Sub


    Sub UpdateData()
    '
    '
    ActiveWorkbook.RefreshAll
    End Sub

    Sub UpdateLinks1()
    '
    '

    ActiveWorkbook.UpdateLink Name:= _
    "U:\Finance\Reporting\Dailies\Data\Budgets 2012.xlsx", Type:= _
    xlExcelLinks
    End Sub

    Sub UpdateLinks2()
    '
    '

    ActiveWorkbook.UpdateLink Name:= _
    "U:\Finance\Reporting\Dailies\Data\Dailies Data.xlsx", Type:=xlExcelLinks
    End Sub

    Sub UpdateForToday()
    '
    Call FreezeYesday
    Call UpdateData
    Call UpdateLinks1
    Call UpdateLinks2

    End Sub

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro Runs in Debug Mode but give run-time error 1004 when called from control object

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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