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
thanks. you did answer my question, but how about taking the first line of the first paragraph and copy it as an independent line at the beginning, and strip off all nonalphabetical characters. please see attached image.
Apr 19, 2022
Does the first line always start with a numeral, followed by a period as in the
1. Den Hirten, die bei Nacht,
and you want to reduce that to
Den Hirten die bei Nacht
1. Den Hirten, die bei Nacht,
and you want to reduce that to
Den Hirten die bei Nacht
- Josh_WaldnerApr 19, 2022Brass Contributoryes, 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, 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