saveas file method error

pjmsimmons

Board Regular
Joined
Dec 13, 2011
Messages
80
Hi All,
I am having a little trouble with the following code. It keeps failing at this line:
wbNew.SaveAs Filename:=savefilename, FileFormat:=6

can anyone help?

regards,

Paul



VBA Code:
Set wb = ThisWorkbook  'Name of the workbook you are copying from
Set ws = wb.Sheets("Sample Sheet1") 'Name of sheet you are copying

'adds New Workbook
Set wbNew = Workbooks.Add
wb.Activate

'copies sheet to new workbook
    wb.Sheets("Sample Sheet1").Copy Before:=wbNew.Sheets(1)
   With wbNew.Sheets("Sample Sheet1").UsedRange
    .Value = .Value
    'converts formulas to values
   End With
    
'Prints out Assignment sheet
wb.Worksheets("Assignment Sheet1").PrintOut


'Save as dialog box to save as CSV file
savefilename = "R:\SAMPLE SHEETS\2020\" & wbNew.Worksheets("Sample Sheet1").Range("F16").Value & ".csv"
wbNew.SaveAs Filename:=savefilename, FileFormat:=6
wbNew.Close
MsgBox "New Run Sheet Created and Saved As" & savefilename
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top