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
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