File conversion and renaming

J

Jaymac

I am having to convert a number of files from works (.wps) to word (.doc) and
want to use the same name as the .wps file with the .doc extension.

I am trying to use the following routine:

ActiveDocument.SaveAs , , FileFormat:=wdFormatDocument,
LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="",
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False,
SaveFormsData _
:=False, SaveAsAOCELetter:=False

but the file is still saved with the .wps extension.

Any ideas guys and gals.

Many thanks

Jack
 
J

Jay Freedman

Just changing the FileFormat parameter in the SaveAs command won't
change the extension (that's a bit of magic the Save As dialog does,
but VBA doesn't). You have to fill in the FileName parameter with what
you want.

Besides the FileName and FileFormat parameters, you don't need any of
the others unless you want a non-default value.

Try this:

Dim NewFilename As String
NewFilename = ActiveDocument.Name
'replace the extension
NewFilename = Left$(NewFilename, Len(NewFilename) - 3) & "doc"
ActiveDocument.SaveAs FileName:=NewFilename, _
FileFormat:=wdFormatDocument

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
H

Helmut Weber

Hi Jaymac,

like this:

Sub Macro5()
Dim sNam As String
sNam = ActiveDocument.Name
sNam = Left(sNam, Len(sNam) - 3)
sNam = sNam & "doc"
ActiveDocument.SaveAs sNam, FileFormat:=wdFormatDocument
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Jaymac

Many thanks for your response - I had just worked it out by reference to the
help files when you posted your fix.

Thanks again

Jack
 
J

Jaymac

Many thanks for your response - I had just worked it out by reference to the
help files when you posted your fix.

Thanks again for your help

Jack
 

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