Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-02-2015, 08:53 AM
MaheshBabu MaheshBabu is offline Convert word to pdf Windows 8 Convert word to pdf Office 2003
Novice
Convert word to pdf
 
Join Date: Apr 2015
Posts: 1
MaheshBabu is on a distinguished road
Default Convert word to pdf

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....
Reply With Quote
  #2  
Old 04-02-2015, 11:33 PM
gmayor's Avatar
gmayor gmayor is offline Convert word to pdf Windows 7 64bit Convert word to pdf Office 2010 32bit
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 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
Reply With Quote
Reply



Similar Threads
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
Convert word to pdf Convert word document to pdf Catty Word VBA 1 12-11-2013 03:57 PM
Convert word to pdf How to convert HTML to Word doc trtrtre Word 1 12-27-2011 07:26 PM
Convert word to pdf How to convert PDF to word on Mac? priya Word 1 10-07-2011 11:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:07 AM.


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