Forum Discussion
Josh_Waldner
Apr 16, 2022Brass Contributor
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. ...
- Apr 19, 2022Use:
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
Josh_Waldner
Apr 19, 2022Brass Contributor
yes, it always start with "1. ", but it might have commas, periods, exclamation points and other punctuation, which i want to get rid of in the title line.
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
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