logandiana
Board Regular
- Joined
- Feb 21, 2017
- Messages
- 107
I've created a workbook similar to many that I've created in the past.
For some reason, the code in this workbook will stop at the same spot about 50% of the time.
Here's an abbreviated portion of the code that includes issue:
When the code gets to RFID.Sheets(ArrayOne).Copy I get a Microsoft message that says File not found: C:\Users\user\Appdata\Local\Temp\VB7284.tmp
If I click on that then it moves to a VBA run time error Method 'Copy' of object 'Sheets' failed and is highlighted on the above mentioned RFID.Sheets(ArrayOne).Copy
This is my first time using, the sheets in a named array. Previously I've always just done Sheets(Array("","","")).copy ,but I was getting the same errors that way as well.
I guess I could understand if this failed every time, but the fact that it works about half of the time really has me puzzled. Is my file corrupt or something?
For some reason, the code in this workbook will stop at the same spot about 50% of the time.
Here's an abbreviated portion of the code that includes issue:
VBA Code:
Dim RFID As Workbook
Dim exp, rep3, rep4, rep7, rep5, rep6, rep8, CP, WIN As Worksheet
Dim LR, LR1 As Long
Dim rgDT, rgCR, rgOP As Range
Dim shp As Shape
Dim ArrayOne, ArrayTwo As Variant
Sub DoStuff()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set RFID = ThisWorkbook
Set exp = RFID.Sheets("export")
Set rep3 = RFID.Sheets("3000")
Set rep4 = RFID.Sheets("4000")
Set rep7 = RFID.Sheets("7000")
Set rep5 = RFID.Sheets("5000")
Set rep6 = RFID.Sheets("6000")
Set rep8 = RFID.Sheets("8000")
Set CP = RFID.Sheets("CAMs progress")
Set WIN = RFID.Sheets("week in numbers")
...
ArrayOne = Array("export", "3000", "4000", "5000", "6000", "7000", "8000")
ArrayTwo = Array("week in numbers", "CAMs progress")
RFID.Sheets(ArrayOne).Copy
ActiveWorkbook.SaveAs Filename:=RFID.Path & "\completed\" & "RFID Status " & Format(Now(), "YYYY-MM-DD hh.mm AMPM") & " " & ".xlsx", FileFormat:=xlOpenXMLWorkbook
RFID.Activate
RFID.Sheets(ArrayTwo).Copy
ActiveWorkbook.SaveAs Filename:=RFID.Path & "\completed\" & "RFID CAM and Region " & Format(Now(), "YYYY-MM-DD hh.mm AMPM") & " " & ".xlsx", FileFormat:=xlOpenXMLWorkbook
...
When the code gets to RFID.Sheets(ArrayOne).Copy I get a Microsoft message that says File not found: C:\Users\user\Appdata\Local\Temp\VB7284.tmp
If I click on that then it moves to a VBA run time error Method 'Copy' of object 'Sheets' failed and is highlighted on the above mentioned RFID.Sheets(ArrayOne).Copy
This is my first time using, the sheets in a named array. Previously I've always just done Sheets(Array("","","")).copy ,but I was getting the same errors that way as well.
I guess I could understand if this failed every time, but the fact that it works about half of the time really has me puzzled. Is my file corrupt or something?