Consulting

Results 1 to 3 of 3

Thread: Solved: How to handle "automatic links" alert when driving Excel with VBScript?

  1. #1
    VBAX Regular
    Joined
    Apr 2007
    Location
    Sector ZZ 9 Plural Z Alpha
    Posts
    6
    Location

    Solved: How to handle "automatic links" alert when driving Excel with VBScript?

    I am writing Excel driver scripts to automate open/button press/save/close of spreadsheets. I'm doing this in classic vbscript. We schedule these to run overnight without human supervision.

    Recently I ran into a workbook that gives the following alert when opening
    The workbook you opened contains automatic links to information in
     another workbook. Do you want to update this workbook with changes
     made to the other workbook?
    
    * To update all linked information, click Yes.
    * To keep the existing information, click No.
    How can my automation script instruct Excel to NOT update the links (as if I clicked "No")? (There's quite a lot of information out there about finding and removing links.... but I don't want to do that.)

    I can disable the alert [vba]ExcelObj.AskToUpdateLinks = false[/vba] but then Excel acts like I clicked "yes".

    I have code similar to the following.[vba]
    Dim ExcelObj
    Dim WorkBookObj
    Set ExcelObj = CreateObject("EXCEL.APPLICATION")

    'disable "Automatic links" dialog
    ExcelObj.AskToUpdateLinks = False

    'set automatic links to false
    '<<<<<<<<<<<<<<<<<<<<<<<<<<< HOW?

    Set WorkBookObj = ExcelObj.Workbooks.Open("myBook.xls")

    'disable auto-calc
    ExcelObj.Calculation = -4135

    'Do work
    ExcelObj.Worksheets("mySheet").myFunction()
    WorkBookObj.save
    WorkBookObj.close(false)

    'Clean up
    ExcelObj.quit
    Set WorkBookObj = nothing
    Set ExcelObj = nothing

    [/vba]
    Please help me. This is driving me nuts!

  2. #2
    VBAX Regular
    Joined
    Apr 2007
    Location
    Sector ZZ 9 Plural Z Alpha
    Posts
    6
    Location
    Figures I'd figure it out right after posting

    Change
    [vba]Set WorkBookObj = ExcelObj.Workbooks.Open("myBook.xls")[/vba]
    To
    [vba]Set WorkBookObj = ExcelObj.Workbooks.Open("myBook.xls",0)[/vba]

    The Open method takes a parameter "UpdateLinks" that controls updating...

    UpdateLinks Optional Variant. Specifies the way links in the file are updated. If this argument is omitted, the user is prompted to specify how links will be updated. Otherwise, this argument is one of the values listed in the following table.

    Value Meaning
    0 Doesn't update any references
    1 Updates external references but not remote references
    2 Updates remote references but not external references
    3 Updates both remote and external references
    I hope this post will save someone else some pain in the future.

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I hope this post will save someone else some pain in the future
    Thanks for posting your solution......good to know.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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