|
-
May 27th, 2005, 01:11 PM
#1
Thread Starter
Member
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:
Sub FindMe()
Dim oApp As Object
Dim oWB As Object
Set oApp = CreateObject("Excel.Application")
oApp.Visible = True
Set oWB = oApp.Workbooks.Open("C:\filename.xls")
MsgBox oWB.Sheets(1).Cells(6, 15).Value
oWB.Close
Set oWB = Nothing
oApp.Quit
Set oApp = Nothing
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.
-
May 27th, 2005, 01:20 PM
#2
Re: Using VBA to open an excel file (updating problem)
Here you go.
VB Code:
Sub FindMe()
Dim oApp As Object
Dim oWB As Object
Set oApp = CreateObject("Excel.Application")
oApp.Visible = True
Set oWB = oApp.Workbooks.Open("C:\filename.xls", [color=red]3[/color])
MsgBox oWB.Sheets(1).Cells(6, 15).Value
oWB.Close
Set oWB = Nothing
oApp.Quit
Set oApp = Nothing
End Sub
'UpdateLinks 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
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|