I have the following code, working except that its not saving the new spreadsheet in the correct folder. (instead it is saving it to My Documents folder). I need it to save in the parent folder of the initial spreadsheet.
I added a line (now commented out) that does save the file in the correct path, but then the macro does a dump and fails further down the line.
Sub CreatePO()
'copy sheet to new workbook
Dim wb As Workbook
abc = ActiveSheet.Name
Sheets("formulas").Range("AB1") = Sheets(abc).Range("I39")
Set wb = Workbooks.Add
ThisWorkbook.ActiveSheet.Copy Before:=wb.Sheets(1)
'save workbook as xlsm
wb.SaveAs ActiveSheet.Name, FileFormat:=52
'wb.SaveAs ThisWorkbook.Path & "\" & abc, FileFormat:=52
Dim openworkbook
Dim x1
Dim FNametxt As String, FNamefrm As String, FileSelected As String, FileName As String
With ThisWorkbook
Let FNametxt = .Path & "\PO\code.txt"
.VBProject.VBComponents("Module1").Export FNametxt
Let FNamefrm = .Path & "\PO\form.frm"
.VBProject.VBComponents("UserForm1").Export FNamefrm
Let FNamecal = .Path & "\PO\calendar.frm"
.VBProject.VBComponents("frmCalendar").Export FNamecal
End With
Workbooks.Open abc
Sheets(abc).Activate
ActiveWorkbook.VBProject.VBComponents.Import FNametxt
ActiveWorkbook.VBProject.VBComponents.Import FNamefrm
ActiveWorkbook.VBProject.VBComponents.Import FNamecal
ActiveWorkbook.Save
Set openworkbook = Workbooks.Open(abc)
Application.ScreenUpdating = False
With ThisWorkbook
.Sheets("Formulas").Copy Before:=openworkbook.Sheets(1)
.Sheets("Master").Copy Before:=openworkbook.Sheets(1)
.Sheets("BigMaster").Copy Before:=openworkbook.Sheets(1)
.Sheets("Estimating1").Copy Before:=openworkbook.Sheets(1)
.Activate
End With
'close purchase order-template, DONT SAVE
Workbooks("Purchase Order-template.xlsm").Activate
'Application.DisplayAlerts = False
'ActiveWorkbook.Close
'Application.DisplayAlerts = True
'another way to close the file without seeing any prompts
Workbooks("Purchase Order-template.xlsm").Close SaveChanges:=False
End Sub
when i uncomment out this line, the macro fails
'wb.SaveAs ThisWorkbook.Path & "\" & abc, FileFormat:=52
can anyone help me with this?
Bookmarks