Forum Discussion

Josh_Waldner's avatar
Josh_Waldner
Brass Contributor
Apr 16, 2022

Save as

Hi. I need  little help with a VBA code to save a document as a .doc(x) with the first line of the document as the title. The document is originally a .txt file with a number as a name. ei: 563.txt. ...
  • Doug_Robbins_Word_MVP's avatar
    Doug_Robbins_Word_MVP
    Apr 19, 2022
    Use:

    Dim fname As String
    Selection.HomeKey wdStory
    With ActiveDocument
    fname = LTrim(Mid(.Bookmarks("\line").Range.Text, 3))
    fname = Replace(fname, ",", "")
    fname = Replace(fname, ".", "")
    fname = Replace(fname, "?", "")
    fname = Replace(fname, "!", "")
    .SaveAs2 fname & ".docx"
    End With

Resources