Saving as 2 file types with active workbook name

YeshyTiger

New Member
Joined
Oct 21, 2008
Messages
23
Hello,

I'm trying to save multiple workbooks as both .xls and .csv I recieve .xls files, make consistent changes, then save the updated workbook in both formats in seperate folder. How can I do this in VBA? I want to keep the same name as what I opened the file as

My current isn't cutting it. Also, there are times when I get 2 workbooks of the same name and I just want to overwrite what's already in the folder.

Here's my current, it's a section out of my much larger macro.

Code:
 Application.DisplayAlerts = False
ChDir "C:\Documents and Settings\jgeiger\Desktop\PMP Converted Files"
 ActiveSheet.SaveAs Filename:=ActiveWorkbook.Name, FileFormat:=xlNormal
ChDir "C:\Documents and Settings\jgeiger\Desktop\CSV Ready for Import"
ActiveSheet.SaveAs Filename:=ActiveWorkbook.Name, FileFormat:=xlCSV
 

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.
To overwrite an existing file, use KILL, e.g.

Code:
Kill "C:\Documents and Settings................filename"

Insert this immediately before your save command.
 
Upvote 0
But the file name(s) change with each file. Could I put a Kill activeworksheet.name in there?

ie
Code:
Kill "C:\Documents and Settings................activeworksheet.name"

It is not actually killing the open worksheet, just killing a file of same name in different folder
 
Upvote 0
Isn't that going to overwrite the first file with the second? Just using chdir will not set that as the place to save a file as far as I am aware.

Try this, I did it in notepad so you may need to play around with it a little:

Code:
Application.DisplayAlerts = False
ActiveSheet.SaveAs Filename:="C:\Documents and Settings\jgeiger\Desktop\PMP Converted Files\" & ActiveWorkbook.Name, FileFormat:=xlNormal
ActiveSheet.SaveAs Filename:="C:\Documents and Settings\jgeiger\Desktop\CSV Ready for Import\" & left(ActiveWorkbook.Name,len(ActiveWorkbook.Name)-4) & ".csv", FileFormat:=xlCSV
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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