Hi
I use vba from a module in an access database to store data from excel workbooks to the database.
This works great except if anybody in my house trys to use excel whilst this code is running.
When that happens the newly opened workbook takes focus and my code hangs.
I think I need to open a hidden dummy instance of excel before I loop through my workbooks but am not sure how to do this.
Any help would be appreciated. Thanks
This is the code I use at the moment.
Thanks Dgs2001
I use vba from a module in an access database to store data from excel workbooks to the database.
This works great except if anybody in my house trys to use excel whilst this code is running.
When that happens the newly opened workbook takes focus and my code hangs.
I think I need to open a hidden dummy instance of excel before I loop through my workbooks but am not sure how to do this.
Any help would be appreciated. Thanks
This is the code I use at the moment.
Code:
Dim objFSO As Object
Dim appExcel As Excel.Application
Dim wb As Excel.Workbook
Dim objFolder As Object
Dim objFile As Object
Dim usr As String
usr = Environ$("UserName")
path = "C:\Users\" & usr & "\Documents\tempSheets"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set appExcel = Excel.Application
appExcel.DisplayAlerts = False
' check how many files we are processing
fc = CountFiles(path)
Debug.Print "File Count " & fc
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder(path)
'Loop through the Files collection
For Each objFile In objFolder.Files
Debug.Print (vbNewLine & "files to process " & fc & vbNewLine)
Debug.Print (objFile & vbNewLine)
Set wb = appExcel.Workbooks.Open(objFile)
'''' Import the data to the database
Next
'''Close and release everything.
Thanks Dgs2001