Hi there,
I hope someone may be able to help me please?
I have a workbook (workbook A) with lots of data in.
A second workbook (workbook B) is to be found in a location which doesn't change, opened, some sheets copied over and for it to be saved as a copy in the same location as workbook A. I have a code to do this and it seemed to work perfectly.
However I have added a third workbook, workbook C which I want exactly the same thing to happen as with workbook B. The data copied will be slightly different but the process is the same.
When I use the same code for workbook C I don't get a VBA error but it says the excel needs to close and about an error report - could anyone help me with the reason why please and how I can fix it?
My current code is below. Many thanks.
Sub Proceed()
Dim newpathway As String
Application.ScreenUpdating = False
With Sheets("Sheet3")
.Cells.Copy
.Cells.PasteSpecial Paste:=xlValues
End With
On Error Resume Next
ActiveWorkbook.Names("Name1").Delete
ActiveWorkbook.Names("Name2").Delete
ActiveWorkbook.Names("Name3").Delete
On Error GoTo 0
newpathway = ThisWorkbook.Path
WorkbookB
Workbooks("WorkbookA.xlsm").Activate
newpathway = ThisWorkbook.Path
WorkbookC
Workbooks("WorkbookA.xlsm").Activate
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Sheet5").Delete
On Error GoTo 0
Application.DisplayAlerts = True
MsgBox ("Please continue in the new workbooks")
Exit Sub
Application.ScreenUpdating = True
End Sub
Sub WorkbookB()
Dim excelfile As String
Dim newpathway As String
excelfile = "WorkbookB.xlsm"
Workbooks.Open "C:\My Documents" & excelfile
Workbooks("WorkbookA.xlsm").Activate
Sheets(Array("Sheet1", "Sheet3")).Copy After:=Workbooks("WorkbookB.xlsm").Sheets("Front Page")
Workbooks("WorkbookB.xlsm").Activate
Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs Filename:=newpathway & ActiveWorkbook.Name
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
Sub WorkbookC()
Dim excelfile As String
Dim newpathway As String
excelfile = "WorkbookC.xlsm"
Workbooks.Open "C:\My Documents\" & excelfile
Workbooks("WorkbookA.xlsm").Activate
Sheets(Array("Sheet2", "Sheets3", "Sheet4", "Information")).Copy After:=Workbooks("WorkbookC.xlsm").Sheets("Front Page")
Workbooks("WorkbookC.xlsm").Activate
Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs Filename:=newpathway & ActiveWorkbook.Name
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
Bookmarks