Help with saving a filename in VBA

T

teepee

If i want to write a macro to save a file as filename x.csv where x is the
value contained in cell b2, I tried

ActiveWorkbook.SaveAs Filename:= _
"filename "& $b$2 &".csv", FileFormat:=xlCSV,
CreateBackup:=False

but I'm obviously messing up the syntax. Could anyone set me straight
please? And is there a command to return me to filename.xls afterwards to
continue working?

Many thanks
 
G

Gary''s Student

Adapted from the Recorder:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2/19/2008 by James Ravenswood
'
v = Range("B2").Value
'
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\Owner\My Documents\filename" & v & ".csv",
FileFormat:=xlCSV, _
CreateBackup:=False

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\Owner\My Documents\filename" & v & ".xls",
FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub
 
J

Jim Cone

I think he is just teasing us. <g>

Princeton's directory for faculty / students does not have that name.
(Princeton was mentioned in a previous post)

gnsu: "Gyeongsang National University" does not have a directory
available on their English web site.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Gord Dibben" <gorddibbATshawDOTca>
wrote in message
So we finally get a look at the name of Gary's Student?
Gord
 
G

Gord Dibben

Could be but the macro recorder doesn't lie<g>

Although one can enter anything in Tools>Options>General>User Name if he wants
to tease.


Gord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top