Link to home
Start Free TrialLog in
Avatar of chigh
chighFlag for United States of America

asked on

Using MS Word FileSaveAs macro from the command line.

How do I start MS Word from the command line and instruct it to save a specified *.rtf file as a *.doc file without having to make additional keyboard or mouse entries?

I'm trying to start Word with the FileSaveAs macro ...
Winword.exe /mFileSaveAs MyFile.rtf
... and I want Word to create MyFile.doc.  But when it runs the macro, it pops up the "Save As" window, requiring operator interaction.  Is there a way I can tell the FileSaveAs macro what to do from the command line?

My environment is Windows 2000, MS Word 2000.
Avatar of William Elliott
William Elliott
Flag of United States of America image

where strvariable is the "myfile" name

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

Write your macro like this:

Sub MyFileSave()
    Dim strName As String
    Dim strStem As String
    Dim strNewName As String
   
    strName = ActiveDocument.Name
    strStem = Split(strName, ".")(0)
    strNewName = strStem & ".rtf"
    ActiveDocument.SaveAs strNewName, wdFormatRTF
End Sub
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial