Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2023, 01:52 PM
Kvemperor Kvemperor is offline Need to make a word document in pdf form Windows 10 Need to make a word document in pdf form Office 2021
Novice
Need to make a word document in pdf form
 
Join Date: May 2023
Posts: 2
Kvemperor is on a distinguished road
Default Need to make a word document in pdf form

Is there a vba code so i can convert a word document into pdf? If i succedd with the code then i will have the macro in the ribbon and every time i want to make a word into pdf i will press the macro button


Thank you in advance
Reply With Quote
  #2  
Old 05-06-2023, 10:52 PM
gmayor's Avatar
gmayor gmayor is offline Need to make a word document in pdf form Windows 10 Need to make a word document in pdf form Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will work
Code:
Sub SaveAsPDF()
'Graham Mayor - https://www.gmayor.com - Last updated - 07 May 2023 

Dim strDocName As String
Dim strPath As String
Dim intPos As Integer
Start:
    'Find position of extension in filename
    strDocName = ActiveDocument.Name
    strPath = ActiveDocument.path & "\"
    intPos = InStrRev(strDocName, ".")
    If intPos = 0 Then
        ActiveDocument.Save
        GoTo Start
    End If
    strDocName = Left(strDocName, intPos - 1)
    strDocName = strPath & strDocName & ".pdf"

    ActiveDocument.ExportAsFixedFormat OutputFileName:=strDocName, _
                                       ExportFormat:=wdExportFormatPDF, _
                                       OpenAfterExport:=False, _
                                       OptimizeFor:=wdExportOptimizeForPrint, _
                                       Range:=wdExportAllDocument, From:=1, To:=1, _
                                       Item:=wdExportDocumentContent, _
                                       IncludeDocProps:=True, _
                                       KeepIRM:=True, _
                                       CreateBookmarks:=wdExportCreateHeadingBookmarks, _
                                       DocStructureTags:=True, _
                                       BitmapMissingFonts:=True, _
                                       UseISO19005_1:=False
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 05-07-2023, 01:19 AM
Kvemperor Kvemperor is offline Need to make a word document in pdf form Windows 10 Need to make a word document in pdf form Office 2021
Novice
Need to make a word document in pdf form
 
Join Date: May 2023
Posts: 2
Kvemperor is on a distinguished road
Default Export word to pdf

thank you very much my friend.it worked perfectly .the only problem was when i run it ,it didn t happen anything so i changed the third line from false to true(OpenAfterExport)
Now when i run it ,it opens directly the document in pdf form
Again thank you very much
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to make a word document in pdf form make small numbers above at the end of a word in document Nosilah Word 5 03-17-2022 02:57 PM
How to Make Userform Copy From One Word Document to Another Marrick13 Word VBA 0 03-19-2018 10:45 AM
Need to make a word document in pdf form How to make uneditable but fillable document in word 2003? officeboy09 Word 1 01-22-2014 03:54 PM
Need to make a word document in pdf form How to make a word italics throughout document Aless Word 6 06-24-2013 08:32 AM
Need to make a word document in pdf form Need to make sure all images are 300+ dpi in word document Ralph Drawing and Graphics 3 08-20-2011 03:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft