So I'm working on a program to take in data ".txt" format and read certain values and then take those values place them in an outside report that is formatted to a standard document my company uses. Then copy the formatted document and save them in a separate workbook, from both of those, that will be a collective database of the formatted sheets for review or print out later.
Obviously I have dumb down this code to just the guts of where my problem is occurring but it still represents what my basic idea is and causing the same alarm as the larger file.
Sub Begin()
Workbooks.Open Filename:="C:\Users\CNCLathe.MANDA\Desktop\XL\COPYING\Report1.xlsx"
Workbooks.Open Filename:="C:\Users\CNCLathe.MANDA\Desktop\XL\COPYING\Report2.xlsx"
'---------------------------------------------------------------------------------
'The File With the Sub Program organizing information
Set W1 = Workbooks("TEST.xlsm")
'The File With the Formatted Worksheet
'Changes will not be saved when it closes
Set W2 = Workbooks("Report1.xlsx")
'The File with all the new formatted worksheets added to it
Set W3 = Workbooks("Report2.xlsx")
'---------------------------------------------------------------------------------
'pretending to add data to formatted file as I will later
W2.Sheets("Sheet1").Cells(2, 2).Value = 999
'then I need to copy the formated worksheet[as values]
'and add it to Report2
'Error Occurs here
W2.Sheets("Sheet1").Copy After:=W1.Sheets(wb.Sheets.Count)
'ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value
Workbooks("Report1.xlsx").Activate
MsgBox ("OPEN")
'ActiveWorkbook.Save
ActiveWorkbook.Close SaveChanges:=False
End Sub
Where is
wb
defined? Perhaps instead ofwb.Sheets.Count
, tryW1.Sheets.Count