Consulting

Results 1 to 5 of 5

Thread: Print to PDF and then rename

  1. #1

    Print to PDF and then rename

    I've been going through these steps manually each time but it's getting to be a little bit tedious and I love some sort of a VBA/VB solution if someone can help me.

    1) Take the current open document in Word and print to PDF. This requires selecting a different printer from the drop down menu. See screenshot here.

    I realize that MS Word has a built-in functionality to convert a document into PDF, but there are times when I print to this virtual PDF printer for other specific reasons. It's a long story and I don't really want to get into the technical reasons of why.

    2) The virtual printer (shown in screenshot) converts the document to a PDF file and the output is always going to be here:
    E:\Ghost PDF conversions\

    3) The file name is always like this: "Microsoft Word - {saved file name}.docx.pdf"

    For Example: If I have saved the Word doc as "Letter to Mom", the converted filename will read as ""Microsoft Word - Letter to Mom.docx.pdf"
    I put the curly brackets there just to so you guys can see that it varies from file to file (whatever I've saved it as).

    I don't like this format, so then I always end up renaming the file manually which gets very boring and tedious. What I would love is a macro that renames it to:
    Letter to Mom.pdf (Deleting "Microsoft Word -" from the beginning and deleting ".docx" from the middle)

    And then moves the file to:
    G:\Correspondence\

    Any help would be greatly appreciated!

    Running Win7 OS and MS Office 2010 SP2.

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    So neither Word's SaveAs method nor its ExportAsFixedFormat method does what you need?
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Nevermind folks, I'll take this question elsewhere.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    When you do, kindly provide the cross-post links on both forums, as per VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq...._new_faq_item3
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    There is a limit to what can be done with third party PDF tools. The following macro run with the original document on screen, after the PDF has been created, will rename the PDF and put it in the folder required as per your post.
    Sub RenamePDF()
    Dim oDoc As Document
    Dim sName1 As String, sName2 As String
    Const sPath1 As String = "E:\Ghost PDF conversions\"
    Const sPath2 As String = "G:\Correspondence\"
        Set oDoc = ActiveDocument
        oDoc.Save
        sName1 = oDoc.Name
        sName2 = Replace(oDoc.Name, "docx", "pdf")
        sName1 = "Microsoft Word - " & sName1 & ".pdf"
        Name sPath1 & sName1 As sPath2 & sName2
    lbl_Exit:
        Exit Sub
    End Sub
    Alternatively you could consider https://www.gmayor.com/pdfcreator_addin.htm, which will create the PDF, using PDF Creator (linked from the page) with the option of security measures absent from Microsoft's implementation, with the required name and in the folder of your choice.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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