Results 1 to 2 of 2

Thread: Using VBA to open an excel file (updating problem)

  1. #1

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    32

    Resolved Using VBA to open an excel file (updating problem)

    VB Geniuses,

    Based on a suggestion from a previous thread, I have implemented the following lines of code to open an Excel file, extract the data from one of the cells, and close the file:

    VB Code:
    1. Sub FindMe()
    2.     Dim oApp As Object
    3.     Dim oWB As Object
    4.     Set oApp = CreateObject("Excel.Application")
    5.     oApp.Visible = True
    6.     Set oWB = oApp.Workbooks.Open("C:\filename.xls")
    7.     MsgBox oWB.Sheets(1).Cells(6, 15).Value
    8.     oWB.Close
    9.     Set oWB = Nothing
    10.     oApp.Quit
    11.     Set oApp = Nothing
    12. End Sub

    The problem is that this program does not work if the Excel file has links. In this case, Excel asks you if you want to update the links or not and nothing happens. I would like to be able to modify the code to detect if the file will be prompted to update, and to either update or not update the file. Then it should extract the info it needs and save and close the file.

    Thanks,

    VO
    Last edited by ovlia1286; Jun 7th, 2005 at 08:21 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Using VBA to open an excel file (updating problem)

    Here you go.
    VB Code:
    1. Sub FindMe()
    2.     Dim oApp As Object
    3.     Dim oWB As Object
    4.     Set oApp = CreateObject("Excel.Application")
    5.     oApp.Visible = True
    6.     Set oWB = oApp.Workbooks.Open("C:\filename.xls", [color=red]3[/color])
    7.     MsgBox oWB.Sheets(1).Cells(6, 15).Value
    8.     oWB.Close
    9.     Set oWB = Nothing
    10.     oApp.Quit
    11.     Set oApp = Nothing
    12. End Sub
    13. 'UpdateLinks Meaning
    14. '0 Doesn 't update any references
    15. '1 Updates external references but not remote references
    16. '2 Updates remote references but not external references
    17. '3 Updates both remote and external references
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width