Reputation: 63
I am encountering an error on the code that I am working on below.
Sub Pasting
Dim o as integer
Dim i as integer
Dim v as String
o = 1
i = 0
Sheets("Sample").Visible = True
Sheets("Sample").Select
Do While i < 1
Range("A:AA").Select
Selection.Copy
ActiveSheet.Next.Select
On Error Goto PE
Range("A1").Select
Application.DisplayAlerts = False
ActiveSheet.Paste
Application.DisplayAlerts = True
Loop
PE:
Application.CutCopyMode = False
Sheets("Sample").Visible = False
Sheeets("Overall").Select
v = "Sample File" & Format(DateAdd("m",1,Now), "Mmmm yyyy") & ".xlsb"
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & v
End Sub
My Error was a
Run-Time Error 1004
Method 'SaveAs' of object'_Workbook Failed.
Process would be:
You will open the Previous File from the previous month
Click file to Open Sample sheet w/c contains default table
Run the loop until all all sheets from 1 to 30 has been paste with default data
Macro will end loop
Macro will save the file as same file type from the same location with the new month.
Close file and override error messages.
Upvotes: 3
Views: 315
Reputation: 84465
At least three things
ThisWorkbook
.VBA:
Dim v As String
v = "Sample File" & Format(DateAdd("m", 1, Now), "Mmmm yyyy") & ".xlsb"
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & v, FileFormat:=50
Upvotes: 1