macro for saving file

G

Gatorpan

We want to save hundereds of files in .doc and .XML
format. We have created a macro that does this. However
we cannot get the macro to use the orginal file name. We
tried cut and paste etc, but when the macro runs it
always uses the file name from when we created the macro.

How do we get it to take the file name as a variable in
the macro?

Thanks!
 
J

Jay Freedman

The filename of the active document is in the property
ActiveDocument.Name
and the complete path+filename is in the property
ActiveDocument.FullName
You can assign the appropriate one of these to a string variable, make
any needed adjustments (such as replacing ".doc" with ".xml"), and
assign that string variable to the FileName parameter of the
ActiveDocument.SaveAs method.

Dim MyFileName As String
MyFileName = ActiveDocument.Name
MyFileName = Replace(MyFileName, ".doc", ".xml")
ActiveDocument.SaveAs FileName:=MyFileName, _
FileFormat:=wdFormatXML
 

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