locked
How to create a PDF file from VBA or VB6? RRS feed

  • Question

  • How to create a PDF File from VBA or VB6?
    • Moved by Eileen ni Friday, August 30, 2013 1:19 AM move
    Thursday, August 29, 2013 10:04 AM

Answers

  • Hi Jay,

    Which version of Office are you currently using?

    According to your description, you perhaps need to be looking at the .ExportAsFixedFormat Type:=xlTypePDF method if you want to convert an excel to pdf file

    Here's the link to the MSDN page:  

    http://msdn.microsoft.com/en-us/library/office/ff198122.aspx

    I have tested the sample code below with Excel 2013, please have a try with it:

    Sub CreatePDF()        
    
    
    Dim pn$, fn$, ss$
    
    pn = "C:\Doc\" ' type your path here
    
    fn = "TEST"  'type your file name
    
    ss = "Sheet1" 'type your sheet name
    
    ThisWorkbook.Worksheets(ss).ExportAsFixedFormat Type:=xlTypePDF, Filename:=pn & fn & ".pdf", _
    
    Quality:=xlQualityStandard, IncludeDocProperties:=True
    
      
    
    End Sub
    

    As for creating a pdf file from a word, please try with Document.ExportAsFixedFormat Method.

    Here's the link to the MSDN page:  

    http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.exportasfixedformat.aspx

    and I have found a sample code for you below and it is for office 2007;

    http://accessexperts.com/blog/2010/05/13/how-to-create-pdfs-in-word-using-access-vba/

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Hope it can help you!


    Sophia Gou <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED> MSDN Community Support Please remember to "Mark as Answer" the responses that resolved your issue.


    Monday, September 2, 2013 10:05 AM

All replies

  • perhaps you could share what program is hosting your vba code?

    al


    Al Edlund Visio MVP

    Friday, August 30, 2013 1:25 PM
  • Hi Jay,

    Which version of Office are you currently using?

    According to your description, you perhaps need to be looking at the .ExportAsFixedFormat Type:=xlTypePDF method if you want to convert an excel to pdf file

    Here's the link to the MSDN page:  

    http://msdn.microsoft.com/en-us/library/office/ff198122.aspx

    I have tested the sample code below with Excel 2013, please have a try with it:

    Sub CreatePDF()        
    
    
    Dim pn$, fn$, ss$
    
    pn = "C:\Doc\" ' type your path here
    
    fn = "TEST"  'type your file name
    
    ss = "Sheet1" 'type your sheet name
    
    ThisWorkbook.Worksheets(ss).ExportAsFixedFormat Type:=xlTypePDF, Filename:=pn & fn & ".pdf", _
    
    Quality:=xlQualityStandard, IncludeDocProperties:=True
    
      
    
    End Sub
    

    As for creating a pdf file from a word, please try with Document.ExportAsFixedFormat Method.

    Here's the link to the MSDN page:  

    http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.exportasfixedformat.aspx

    and I have found a sample code for you below and it is for office 2007;

    http://accessexperts.com/blog/2010/05/13/how-to-create-pdfs-in-word-using-access-vba/

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Hope it can help you!


    Sophia Gou <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED> MSDN Community Support Please remember to "Mark as Answer" the responses that resolved your issue.


    Monday, September 2, 2013 10:05 AM