Hello,
I have 4 excel files I run /w VBA to import. The issue is 2 of the files have their worksheet name change every day by the system I am exporting them from. My original macro was very simple...
So the problem would be the saved imports dont work for those 2 files since the worksheet name changed. So I was able to create a file in excel /w this macro...
So now my problem is it is in excel... I don't know if it is even possible to write that up in access to be honest. I tried patching that up by doing this....
But when I run this I get a runtime error 440 Automation Error /w
xl.Run "UpdateSheets.xlsm!Update". The macro runs... but once it is done is when it throws the automation error. If I run it myself from excel it works so I am stumped.... any easier way to work around the changing worksheet name issue?
I have 4 excel files I run /w VBA to import. The issue is 2 of the files have their worksheet name change every day by the system I am exporting them from. My original macro was very simple...
Code:
DoCmd.RunSavedImportExport "123"
DoCmd.RunSavedImportExport "456"
DoCmd.RunSavedImportExport "789"
So the problem would be the saved imports dont work for those 2 files since the worksheet name changed. So I was able to create a file in excel /w this macro...
Code:
Sub Update()
Const fPath As String = "C:\Access\Volumes\"
Dim sh As Worksheet
Dim sName As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
sName = Dir(fPath & "*.xls*")
Do Until sName = ""
If Not sName = "UpdateSheets.xlsx" Then
With GetObject(fPath & sName)
.Sheets(1).Name = "1"
.Close True
End With
End If
sName = Dir
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
So now my problem is it is in excel... I don't know if it is even possible to write that up in access to be honest. I tried patching that up by doing this....
Code:
Dim xl As Object
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open ("C:\Access\Volumes\UpdateSheets.xlsm")
xl.Visible = True
xl.Run "UpdateSheets.xlsm!Update"
xl.ActiveWorkbook.Close (True)
xl.Quit
Set xl = Nothing
But when I run this I get a runtime error 440 Automation Error /w
xl.Run "UpdateSheets.xlsm!Update". The macro runs... but once it is done is when it throws the automation error. If I run it myself from excel it works so I am stumped.... any easier way to work around the changing worksheet name issue?