VBA Save As Current File Name

skiir10

New Member
Joined
Feb 3, 2018
Messages
7
Hello,

I'm sorry I'm very new to this, but I am having a problem saving as with VBA. I recorded a macro, and have amended a bit from other posts. This is what I have so far. I am trying to save a .txt file as a .csv with the current file name.

But I get a runtime error that it cannot access file.

Any help much appreciated.

Sub Saveas()
'
' Saveas Macro
'


'
ActiveWorkbook.Saveas Filename:= _
"Data/W1/" + ActiveWorkbook.Name + ".csv" _
, FileFormat:=xlCSVUTF8, CreateBackup:=False
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hello,

your problems most likely lay in:
- an incomplete path i.e. C:\ is missing (watch out too: \ is different from /;))
- + symbols should be replaced for ampersand (&) i.e. the concatenation symbol

Then this should do

Code:
Sub Saveas()


Dim wkbpath As String
Dim wkbname As String


    wkbpath = "C:\data\w1\"
    wkbname = ActiveWorkbook.Name


ActiveWorkbook.Saveas Filename:= _
    wkbpath & wkbname & ".csv", FileFormat:=xlCSVUTF8 _
, CreateBackup:=False


End Sub
Hope this helps
 
Last edited:
Upvote 0
Hi winrow,

Thanks for the help. Unfortunately, I am still getting a run-time error '1004' and cannot access the CR1.rda.csv

Thanks
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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