Hi
I have cobbled together from several sources code that hopefully copies a range ("AA1:AN1000") from an open worksheet/ workbook and opens a new blank workbook and copies and pastes as formats & values into the new workbook, saves this to a set directory and closes this file.
This is what I have with the line that is causing me issues in red:-
Sub CreateNewWorkbookWithValues()
Dim dirPath, fName As String, newWb As Workbook, thisWb As Workbook
Set thisWb = ThisWorkbook
dirPath = thisWb.Path
fName = ActiveSheet.Range("M2").Value
Application.ScreenUpdating = False
Set newWb = Workbooks.Add
thisWb.Sheets("Summary").Range("AA1:AN1000").Copy newWb.Sheets("Sheet1").Range("A1")
newWb.SaveAs Filename:=NewBook.Worksheets("Sheet1").Range("M1").Value
newWb.Close
Application.ScreenUpdating = True
MsgBox "Workbook created at:" & vbCrLf & vbCrLf & dirPath & "\" & fName
End Sub
It opens a new worksheet/ workbook, copies and pastes but then cannot save the file.
Also, how would I change the code to save it to a particular folder and not just the folder that the original file is saved in
Thanks in advance
I have cobbled together from several sources code that hopefully copies a range ("AA1:AN1000") from an open worksheet/ workbook and opens a new blank workbook and copies and pastes as formats & values into the new workbook, saves this to a set directory and closes this file.
This is what I have with the line that is causing me issues in red:-
Sub CreateNewWorkbookWithValues()
Dim dirPath, fName As String, newWb As Workbook, thisWb As Workbook
Set thisWb = ThisWorkbook
dirPath = thisWb.Path
fName = ActiveSheet.Range("M2").Value
Application.ScreenUpdating = False
Set newWb = Workbooks.Add
thisWb.Sheets("Summary").Range("AA1:AN1000").Copy newWb.Sheets("Sheet1").Range("A1")
newWb.SaveAs Filename:=NewBook.Worksheets("Sheet1").Range("M1").Value
newWb.Close
Application.ScreenUpdating = True
MsgBox "Workbook created at:" & vbCrLf & vbCrLf & dirPath & "\" & fName
End Sub
It opens a new worksheet/ workbook, copies and pastes but then cannot save the file.
Also, how would I change the code to save it to a particular folder and not just the folder that the original file is saved in
Thanks in advance