![]() |
#1
|
|||
|
|||
![]()
Hi,
I want a macro for the below requirements : 1. Convert the current page of word document into pdf 2. Should take me by default to Desktop 3. Should allow me to give a file name *** I have the below code, however i have the below challenges: a. entire word document is getting convert instead of current page b. by default taking me to My documents folder on my system Sub PDF() With Dialogs(wdDialogFileSaveAs) .Name = "Draft_[Topic]_[Date]" .Format = wdFormatPDF .Show End With End Sub Can some help me in editing the above code or give me a new code with above requirements Thanks in advance.... |
#2
|
||||
|
||||
![]()
The following will save the current page as PDF on the desktop with a name you enter in a dialog box. However it won't work in Word 2003 which has no PDF function.
If your message header is correct in that you have Word 2003, you are going to need a PDF application that is programmable from VBA, such as Acrobat or PDFCreator. The following code will not work with either of those. Code:
Option Explicit Private Declare Function SHGetSpecialFolderLocation _ Lib "shell32" (ByVal hwnd As Long, _ ByVal nFolder As Long, ppidl As Long) As Long Private Declare Function SHGetPathFromIDList _ Lib "shell32" Alias "SHGetPathFromIDListA" _ (ByVal Pidl As Long, ByVal pszPath As String) As Long Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal pvoid As Long) Private Const CSIDL_DESKTOP = &H0 Private Const MAX_PATH = 260 Private Const NOERROR = 0 Sub SavePageAsPDF() Dim strPDFName As String Dim orng As Range strPDFName = InputBox("Enter the name for the PDF") If strPDFName = "" Then GoTo lbl_Exit If LCase(Right(strPDFName, 4)) = ".pdf" Then strPDFName = SpecFolder(&H0) & "\" & strPDFName Else strPDFName = SpecFolder(&H0) & "\" & strPDFName & ".pdf" End If ActiveDocument.ExportAsFixedFormat OutputFilename:=strPDFName, _ ExportFormat:=wdExportFormatPDF, _ OpenAfterExport:=True, _ OptimizeFor:=wdExportOptimizeForPrint, _ Range:=wdExportCurrentPage, 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 Private Function SpecFolder(ByVal lngFolder As Long) As String Dim lngPidlFound As Long Dim lngFolderFound As Long Dim lngPidl As Long Dim strPath As String strPath = Space(MAX_PATH) lngPidlFound = SHGetSpecialFolderLocation(0, lngFolder, lngPidl) If lngPidlFound = NOERROR Then lngFolderFound = SHGetPathFromIDList(lngPidl, strPath) If lngFolderFound Then SpecFolder = Left$(strPath, _ InStr(1, strPath, vbNullChar) - 1) End If End If CoTaskMemFree lngPidl lbl_Exit: Exit Function End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Convert Word 2007 macro to work in Word 2003 | Kamaflage | Word VBA | 1 | 02-25-2015 11:40 PM |
How Do I Convert XML to Word? | Synful | Word | 13 | 11-23-2014 02:18 PM |
![]() |
Catty | Word VBA | 1 | 12-11-2013 03:57 PM |
![]() |
trtrtre | Word | 1 | 12-27-2011 07:26 PM |
![]() |
priya | Word | 1 | 10-07-2011 11:03 AM |