![]() |
|
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
How to make uneditable but fillable document in word 2003?
|
officeboy09 | Word | 1 | 01-22-2014 03:54 PM |
How to make a word italics throughout document
|
Aless | Word | 6 | 06-24-2013 08:32 AM |
Need to make sure all images are 300+ dpi in word document
|
Ralph | Drawing and Graphics | 3 | 08-20-2011 03:57 AM |