VBA question

STIRRELL

Board Regular
Joined
Dec 30, 2010
Messages
63
Office Version
  1. 365
Hi all,
I know a very little VBA and I am stuck on this bit of code.
I have a workbook called NTCT_EXPENSE_PAYROLL.xlsm
the spreadsheet name is CSV_FILE

I am trying to automate exporting this spreadsheet to a folder on the C: drive as a CSV file. The folder name is EXPORT
but excel does not like:


wbkExport.SaveAs Filename:="C:\EXPORT.7J1", FileFormat:=xlCSV


Can you help with the correct code to export the spreadsheet named CSV_File to a folder on my C drive named EXPORT? I was also trying to name the file 7J1 ( the payroll batch name)


Please help,
Sharon

I found the code below
Dim NTCT_EXPENSE_PAYROLL As Workbook
Dim CSV_FILE As Worksheet

Set shtToExport = ThisWorkbook.Worksheets("CSV_FILE") 'Sheet to export as CSV
Set wbkExport = Application.Workbooks.Add
shtToExport.Copy Before:=wbkExport.Worksheets(wbkExport.Worksheets.Count)
Application.DisplayAlerts = False 'Possibly overwrite without asking
wbkExport.SaveAs Filename:="C:\EXPORT.7J1", FileFormat:=xlCSV
Application.DisplayAlerts = True
wbkExport.Close SaveChanges:=False
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I'll assume that you want to call your saved sheet "7J1" and not "EXPORT.7J1"

VBA Code:
ThisWorkbook.Sheets("CSV_File").Copy
ActiveWorkbook.SaveAs "C:\EXPORT\7J1.csv", FileFormat:=6
 
Last edited:
Upvote 0
Solution
Thank you so much. I had used a period when I needed a \. it worked perfectly. thank you so much. it worked perfectly :)
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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