Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Macro for Save As File Type (Word 2003)

    Is it possible to create a macro to save any open Word file (e.g., "Example.doc") with its current filename but with file type = Plain Text (i.e., "Example.txt")? Could the file extension be changed as well (e.g., "Example.tex" for a LaTeX file)?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro for Save As File Type (Word 2003)

    To save as a text file, you can use

    Sub SaveAsText()
    Dim strName As String
    strName = ActiveDocument.FullName
    strName = Left(strName, Len(strName) - 3) & "txt"
    ActiveDocument.SaveAs strName, wdFormatText
    End Sub

    Word does not have conversion to LaTex built-in, so unless you have an add-in that takes care of that, it can't be done (just changing the extension to .tex wouldn't make it a LaTex file!)

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Re: Macro for Save As File Type (Word 2003)

    Thank you. (This is for saving LaTeX source files, which are plain text but with a .tex filename extension.)

  4. #4
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts
    In the macro, is it possible to specify the type of encoding for a text file (e.g., Unicode, US ASCII, etc.)?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Yes, if you look up SaveAs in the Word VBA help, you'll see that you can specify wdFormatEncodedText as file format, and specify the encoding in the Encoding argument. Change the line

    ActiveDocument.SaveAs strName, wdFormatText

    to

    ActiveDocument.SaveAs FileName:=strName, FileFormat:=wdFormatEncodedText, Encoding:=msoEncodingUSASCII

    The VBA help and the Object Browser (press F2 and search for msoEncoding) have a list of available encoding constants.

  6. #6
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts
    OK thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •