Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 5 of 5

Thread: Printing a file using VBA code

  1. #1
    Join Date
    11th October 2010
    Posts
    2

    Printing a file using VBA code

    Using the VBA code, I like to print (on the default printer) an existing file called "XYZ.pdf" that resides in the same folder as the Excel file. What would be VBA code for it?

    Important: I am not trying to make a pdf file out of an excel sheet/range. All I want is a VBA macro that prints a specific, existing pdf file (in the same folder as the excel file) to my default printer to print the entire pdf file on paper.
    Computer OS: Windows 7
    Excel Version: Office 2007

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    9th September 2009
    Posts
    1,599

    Re: Printing a file using VBA code

    Take a look at:
    VB:
    Option Explicit 
     
    Declare Function apiShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _ 
    ByVal hwnd As Long, _ 
    ByVal lpOperation As String, _ 
    ByVal lpFile As String, _ 
    ByVal lpParameters As String, _ 
    ByVal lpDirectory As String, _ 
    ByVal nShowCmd As Long) _ 
    As Long 
     
    Public Sub PrintFile(ByVal strPathAndFilename As String) 
         
        Call apiShellExecute(Application.hwnd, "print", strPathAndFilename, vbNullString, vbNullString, 0) 
         
    End Sub 
     
    Sub Test() 
         
        PrintFile ("C:\Test.pdf") 
         
    End Sub 
    
    

  3. #3
    Join Date
    26th April 2007
    Location
    Malaysia
    Posts
    71

    Re: Printing a file using VBA code

    Excel 2003, Windows XP.

    Working nicely for me

    Thank you for sharing.

    Yura

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    11th October 2010
    Posts
    2

    Re: Printing a file using VBA code

    Thank you very much for your help, works perfect.

    Excel Video Tutorials / Excel Dashboards Reports


  5. #5
    Join Date
    16th March 2013
    Posts
    1

    Re: Printing a file using VBA code

    Hi
    Is there anyway you can print to another non-default printer using the above code in windows 7 excel 2010?
    Thanks / Jag

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Printing To A Pdf File
    By jshayler in forum EXCEL HELP
    Replies: 1
    Last Post: February 16th, 2007, 06:26
  2. VBA code for Printing
    By splosczynski in forum EXCEL HELP
    Replies: 3
    Last Post: June 8th, 2006, 06:03
  3. VB code for printing...
    By Mezari in forum EXCEL HELP
    Replies: 4
    Last Post: January 13th, 2006, 18:33
  4. Printing using vba code.
    By Dirk Belgium in forum EXCEL HELP
    Replies: 3
    Last Post: January 14th, 2005, 20:44
  5. VBA Printing Code
    By ShawnIRQL in forum EXCEL HELP
    Replies: 8
    Last Post: October 20th, 2004, 04:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
porno