corinereyes
New member
- Local time
- Today, 13:01
- Joined
- Mar 3, 2013
- Messages
- 12
Hi All,
I have this code that opens and closes an excel file. But before to close i need to refresh an Ms Query in excel the user inputs the criteria and after that the file closes. However, when i try to open the file again via the code (command button in access) it gives me error --> runtime error 1004, Method of Object Global failed. etc...
Thanks so much in advance for your help.
Public Function OpenExcelFile(strFilePath As String) As Boolean
'Required: Tools > Refences: Add reference to Microsoft Excel Object Library
'On Error Resume Next
Dim appExcel As Excel.Application
Dim myWorkbook As Excel.Workbook
Set appExcel = CreateObject("Excel.Application")
Set myWorkbook = appExcel.Workbooks.Open(strFilePath)
appExcel.Visible = True
'Do Something or Just Leave Open
Worksheets("Tmpt").Select
Sheets("tmpt").QueryTables(1).Refresh BackgroundQuery:=False
Workbooks("Finalpay.xls").Close SaveChanges:=False
Set appExcel = Nothing
Set myWorkbook = Nothing
End Function
I have this code that opens and closes an excel file. But before to close i need to refresh an Ms Query in excel the user inputs the criteria and after that the file closes. However, when i try to open the file again via the code (command button in access) it gives me error --> runtime error 1004, Method of Object Global failed. etc...
Thanks so much in advance for your help.
Public Function OpenExcelFile(strFilePath As String) As Boolean
'Required: Tools > Refences: Add reference to Microsoft Excel Object Library
'On Error Resume Next
Dim appExcel As Excel.Application
Dim myWorkbook As Excel.Workbook
Set appExcel = CreateObject("Excel.Application")
Set myWorkbook = appExcel.Workbooks.Open(strFilePath)
appExcel.Visible = True
'Do Something or Just Leave Open
Worksheets("Tmpt").Select
Sheets("tmpt").QueryTables(1).Refresh BackgroundQuery:=False
Workbooks("Finalpay.xls").Close SaveChanges:=False
Set appExcel = Nothing
Set myWorkbook = Nothing
End Function