I have an application where I am loading data from an excel workbook(s) that can have multiple worksheets including hidden worksheets. I want to skip the hidden worksheets.
My issues are:
1) Do I need to actually open excel to read the worksheets? This slows the process. When I have an application with only one sheet in a workbook, I can run this without opening Excel.
2) When this code finishes, an instance of Excel is still running -- this can be seen in the Windows Task Manager. I also get messages that pop up after the processing is completed that states: "File now available". I wish to avoid these messages and not have any instances of Excel running when the application completes.
This is my core code. Please let me know what I can do to improve it. Thanks.
Set objExcel = CreateObject("Excel.Application")
strFileName = filePath & fileName
Set objworkbook = objExcel.Workbooks.Open(strFileName)
Set colWorksheets = objworkbook.Worksheets
Dim a As String
For Each objWorkSheet In colWorksheets
If objWorkSheet.Visible Then ' This keeps hidden files from being processed
DoCmd.TransferSpreadsheet acImport, 8, "tblTempMfgProductData", strFileName, False, strWorkSheetName
' This data is then processed ....
Else
End if
Next
Set colWorksheets = Nothing
objworkbook.Close
Set objworkbook = Nothing
objExcel.Quit
Set objExcel = Nothing
My issues are:
1) Do I need to actually open excel to read the worksheets? This slows the process. When I have an application with only one sheet in a workbook, I can run this without opening Excel.
2) When this code finishes, an instance of Excel is still running -- this can be seen in the Windows Task Manager. I also get messages that pop up after the processing is completed that states: "File now available". I wish to avoid these messages and not have any instances of Excel running when the application completes.
This is my core code. Please let me know what I can do to improve it. Thanks.
Set objExcel = CreateObject("Excel.Application")
strFileName = filePath & fileName
Set objworkbook = objExcel.Workbooks.Open(strFileName)
Set colWorksheets = objworkbook.Worksheets
Dim a As String
For Each objWorkSheet In colWorksheets
If objWorkSheet.Visible Then ' This keeps hidden files from being processed
DoCmd.TransferSpreadsheet acImport, 8, "tblTempMfgProductData", strFileName, False, strWorkSheetName
' This data is then processed ....
Else
End if
Next
Set colWorksheets = Nothing
objworkbook.Close
Set objworkbook = Nothing
objExcel.Quit
Set objExcel = Nothing