Results 1 to 18 of 18

Thread: Saving word file based on first line of text

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    I am also having very similar issue, I am dividing a large word document by sections and saving each section individually as a pdf file. I need to compile the name for the PDF using the first line of the section. The code I have so far is this:


    Sub BreakOnSection()
        ' Used to set criteria for moving through the document by section.
        Application.Browser.Target = wdBrowseSection
        'A mailmerge documents ends with a section break next page.
        'Subtracting one from the section count stop error message.
        For i = 1 To ((ActiveDocument.Sections.Count) - 1)
            'Select and copy the section text to the clipboard
            ActiveDocument.Bookmarks("\Section").Range.Copy
            'Create a new document to paste text from clipboard.
            Documents.Add
            Selection.Paste
            ' Removes the break that is copied at the end of the section, if any.
            Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
            Selection.Delete Unit:=wdCharacter, Count:=1
            ChangeFileOpenDirectory "C:\Documents and Settings\vadim\My Documents\INVAR Technologies\Clients\Gventer"
            DocNum = DocNum + 1
            ActiveDocument.ExportAsFixedFormat OutputFileName:= _
            FirstPara & DocNum & ".pdf", ExportFormat:= _
            wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
            wdExportOptimizeForPrint, Range:=wdExportAllDocument, FROM:=1, To:=1, _
            Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
            CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
            BitmapMissingFonts:=True, UseISO19005_1:=False
            ActiveDocument.Close SaveChanges:=False
            ' Move the selection to the next section in the document
            Application.Browser.Next
        Next i
        ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    End Sub

    The header of each section in the big document look like this:
    "Note for Sofia Kogan on 5/10/2010"

    How can I make that into a file name? The date format will probably have to be restructured as file names in windows can't have "/".

    Any help would be greatly appreciate it.
    Last edited by Aussiebear; 12-26-2024 at 07:27 PM.

Posting Permissions

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