Can't figure out the problem on the following code.. Everything works for sheet 1 properly but sheet 2 isn't copying and pasting. Also, even naming sheet 2 doesn't work. I have changed the names of the files to "---".
Basically the goal here is to save the workbook into a different file name without macros on the new spreadsheet. At present time I have to manually copy and paste the second sheet in before saving again.
PHP Code:
Sub SaveAs_xlsx()
On Error Resume Next
Dim WB1 As Workbook
Dim WB2 As Workbook
Dim newbook As Workbook
Set newbook = Workbooks.Add
newbook.SaveAs "W:\------ " _
& Format(Date, "yyyy-mm-dd"), 51
Set WB1 = Workbooks("--------.xlsm")
Set WB2 = Workbooks("------------- " & Format(Date, "yyyy-mm-dd") & ".xlsx")
WB1.Activate
Sheets(1).Range("A1:P1000").Select
Selection.Copy WB2.Sheets(1).Cells(1, 1)
Sheets(2).Range("A1:P1000").Select
Selection.Copy WB2.Sheets(2).Cells(1, 1)
WB2.Activate
WB2.Sheets(1).Columns("A:P").Select
WB2.Sheets(1).Columns("A:P").EntireColumn.AutoFit
WB2.Sheets(2).Columns("A:P").Select
WB2.Sheets(2).Columns("A:P").EntireColumn.AutoFit
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "-"
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "not working"
Sheets(1).Activate
Sheets(2).Activate
WB2.Save
Call SetPrintFormatCAD
Call SetPrintFormatUSD
WB1.Activate
End Sub
Bookmarks