Consulting

Results 1 to 9 of 9

Thread: Write cell contents into individual pdf's

  1. #1

    Write cell contents into individual pdf's

    Hi,

    I have a word document with one table comprised of two columns and 800+ rows. Each cell of the first column contains a string of characters formatted as <string>.<string>. The corresponding cells in the second column contain formatted text.

    I need to split this table into individual pdf files, one for each row. The string in the first column would become the filename and the corresponding formatted text in the second column would be the file content (with the same format as in the table). So the final output will be over 800 pdf’s (one for each row) with file name from the first column and content from the second.

    Many of the strings in the cells of the first column are longer than 40 characters (not suitable for bookmarks), and the table was not created with mail merge.

    Thanks for any help.

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You could actually use a macro-driven mailmerge for this. See, for example, Send Mailmerge Output to Individual Files in the Mailmerge Tips & Tricks thread at: Mailmerge Tips & Tricks (msofficeforums.com)
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Thanks Paul, I looked and tried to modify the codes you suggested. Unfortunately, unless I am missing something, none of them actually does what I need, because in my case the content of each cell in the second column are different from the others, so the main content of the output files would not be uniform as expected from mail merge.

    I looked at your earlier code in an msofficeforum post "split word document based on bookmarks with each new document title of the bookmark" but for that, I would need to make the string in each cell in the first column a bookmark. That would be 800+ bookmarks with names as the strings, but for that, I think, I would need another macro... so I am pretty much stuck here. Any help would be great!

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    The content of each cell is of no particular consequence. All your table needs to have is a heading row with a name for each column for the mailmerge to use as a data field.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Thanks Paul. I've been playing with different ideas within the overall project. As each of the text blocks (to convert into pdf) is composed of a few bookmarked text blocks from another large document, I decided to go back to the source and try to convert the original bookmarked contents in into individual pdf files. It means about 1,500 bookmarks and corresponding pdf files, so I must automate.

    So the task has changed and boiled down to converting the formatted content of each bookmark of a large document into an individual pdf file (retaining the original format). The bookmark name will be the filename of the corresponding pdf. I could not find any code directly on the task, but I am sure this has been done before, so I do not need to reinvent the wheel with my limited understanding of VBA.

    Thanks for any help
    (The individual pdf files eventually will be placed into a DB and used by a Python application when I eventually get there...)

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Unless you provide sufficient details for us to work with, no-one can hope to provide an efficient solution. For example, how are the bookmarks & documents identified? For all I know, mailmerge is still an option.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    The word document is a large, over 1000 pages of, formatted text. I created bookmarks within the document. These are strings with underscore "_" marks as delimiters for easier readings. The contents of the bookmarks are snippets of text from that document, some only one line, some others are a few lines up to half a page. There are over 1,500 of these bookmarked text snippets which I need to extract into separate pdfs retaining the format of the original text. The actual name of the bookmarks form the filenames of the pdfs.

    Because of my limited understanding of VBA, I would like to find a macro that I can implement without much fiddling. Perhaps I am asking too much, but this is a relatively small part of a project I want to implement in Python (that I am still learning).

    Please, let me know if you need any other details.
    Thanks

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Assuming they're actual Word bookmarks:
    Sub SendBkMksToPDFs()
    Application.ScreenUpdating = False
    Dim DocSrc As Document, DocTgt As Document, StrPth As String, BkMk As Bookmark
    Set DocSrc = ActiveDocument
    With DocSrc
      StrPth = .Path & "\"
      For Each BkMk In .Bookmarks
        Set DocTgt = Documents.Add(Visible:=False)
        With DocTgt
          .Range.FormattedText = BkMk.Range.FormattedText
          .SaveAs2 FileName:=StrPth & BkMk.Name & ".pdf", Fileformat:=wdFormatPDF, AddToRecentFiles:=False
          .Close False
        End With
      Next
    End With
    Set DocTgt = Nothing: Set DocSrc = Nothing
    Application.ScreenUpdating = True
    End Sub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  9. #9
    That's exactly. Thank you so much.

Posting Permissions

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