I have a macro that is looping through the creation of a new workbook, copying a sheet to it from the book running the macro, saving and closing the new workbook with a new name.
I am getting inconsistent results as sometimes it works fine but usually I get a VB error "File not found: 'C:\Users\me\AppData\Local\Temp\VBxxx.tmp'
Every time I click "ok" then "debug" then continue playing the macro it progresses.
It may create 2 successful files or 10 before it errors. I'm typically making under 30 files.
I added a wait command in the macro which seems to help, but it still errors out on me. the code alone works, but in a loop I am unsuccessful. Here is the code:
'''''Copy Out Audit Sheet'''''
Application.DisplayAlerts = False
Dim NewBook As Workbook
FPath = Path
FName = CurrFileName
Set NewBook = Workbooks.Add
ThisWorkbook.Sheets("Production 5S").Copy Before:=NewBook.Sheets(1)
NewBook.SaveAs Filename:=FPath & "" & FName
Workbooks(FName).Close
'''''Wait a second to avoid "File Not Found"
Application.Wait Now + #12:00:05 AM#
Application.DisplayAlerts = True
I am getting inconsistent results as sometimes it works fine but usually I get a VB error "File not found: 'C:\Users\me\AppData\Local\Temp\VBxxx.tmp'
Every time I click "ok" then "debug" then continue playing the macro it progresses.
It may create 2 successful files or 10 before it errors. I'm typically making under 30 files.
I added a wait command in the macro which seems to help, but it still errors out on me. the code alone works, but in a loop I am unsuccessful. Here is the code:
'''''Copy Out Audit Sheet'''''
Application.DisplayAlerts = False
Dim NewBook As Workbook
FPath = Path
FName = CurrFileName
Set NewBook = Workbooks.Add
ThisWorkbook.Sheets("Production 5S").Copy Before:=NewBook.Sheets(1)
NewBook.SaveAs Filename:=FPath & "" & FName
Workbooks(FName).Close
'''''Wait a second to avoid "File Not Found"
Application.Wait Now + #12:00:05 AM#
Application.DisplayAlerts = True