I am having some trouble with this one. I am trying to paste a range, that varies based on a selection from a userform, to a new workbook. The pasting is not working. I've gotten feedback that I need to eliminate the use of activesheet, and name the specific targeted workbook. I don't know how to name it if it is a new workbook. I also don't know how to save it to the users desktop.
Anyways. The code fails here (1st line):
Workbooks("Restaurant Manager -Master.xlsx").Worksheets(wsexport).Activate
Workbooks("Restaurant Manager -Master.xlsx").Worksheets(wsexport).Unprotect
Workbooks("Restaurant Manager -Master.xlsx").Worksheets(wsexport).Range("BA6::BT200").Copy
Below is the full code, with so you can see the action I am trying to take - passing the worksheet name variable from the userform cboExportInvoiceWeek. Ideally, the user clicks a button and a new csv file is created. The only variable I have is the worksheet (one for each week of year). The cell values are static.
Again, my issue is the actual pasting into the new workbook.
Private Sub cmbInvoicesExport_Click()
Application.ScreenUpdating = False
Dim CurrentFileName As String
CurrentFileName = ActiveWorkbook.Name
Debug.Print "Active File: " + CurrentFileName
Dim wsexport As String
wsexport = cboExportInvoiceWeek.Value
Workbooks("Restaurant Manager -Master.xlsx").Worksheets(wsexport).Activate
Workbooks("Restaurant Manager -Master.xlsx").Worksheets(wsexport).Unprotect
Workbooks("Restaurant Manager -Master.xlsx").Worksheets(wsexport).Range("BA6::BT200").Copy
Set NewBook = Workbooks.Add
NewBook.Worksheets("Sheet1").Range("A1").PasteSpecial (xlPasteValues)
NewBook.SaveAs Filename:=NewBook.Worksheets("Sheet1").Range("E3").Value
Application.DisplayAlerts = False
Application.DisplayAlerts = True
Application.CutCopyMode = False
Workbooks(CurrentFileName).Activate
Application.ScreenUpdating = True
End Sub