+ Reply to Thread
Results 1 to 10 of 10

Printing external PDF files based on user input

  1. #1
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Printing external PDF files based on user input

    Hi everyone,

    I have a sheet with two cell ranges for user input: C9:C28 ("Area Column"), which is used for inputing an area code such as AA, BB etc, and E9:E28 ("Quantity Column"), which is used for inputting a quantity.

    Elsewhere on the same sheet, I have a VBA-generated list of all files within a specific directory - eg. C:\Users\ABC\MapsAA.pdf. All files are in PDF format and saved in a single directory.

    If a user inputs AA into cell C9 and 3 into cell E9, then clicks on a "Print Maps" button, this should cause the user's default printer to print 3 copies of C:\Users\ABC\MapsAA.pdf. The user can input up to 20 area codes into C9:C28 and corresponding quantities into E9:E28 and print varying numbers of copies of the required maps.

    Can anyone help with this?

    Many thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Printing external PDF files based on user input

    Hi Andy,

    Very interesting question and quite a few technical challenges. See the attached file (plus a few dummy data files so the file can be tested as is) which is a modified copy of your file. There are complete instructions in the file at the bottom of Sheet1.

    One way to print pdf files is to invoke Acrobat (Reader) from inside Excel. Unfortunately only one copy at a time can be printed. To print multiple copies, the same line must be repeated as required. Acrobat (Reader) prints on the 'Windows Default Printer' by default. Other printers can be invoked if needed.

    An working excerpt of the basic code to do the printing is included below. The full code is included in Sub PrintMapsUsingWindowsDefaultPrinter() in Ordinary Code module ModPrintPdfFiles .
    Please Login or Register  to view this content.
    NOTE: Due to firewall restrictions replace qqq with < above (all qqq are in comments).

    Additional information of note:
    How the software works (tested on a single user system):
    a. The user 'clicks' a Yellow 'CommandButton' which activates Macro PrintMapsUsingWindowsDefaultPrinter() (in Ordinary code module ModPrintPdfFiles) with the proper options.
    b. Each NON-BLANK 'Area' cell is read (along with Quantity, Map File Name, and Pdf File Password if applicable).
    c. A new instance of Acrobat (Reader) is opened to print one copy of a file to the 'Windows Default Printer'.
    This step is repeated as many times as required, until all copies of a file are printed.
    NOTE: The software can be modified to select printers other than the 'Windows Default Printer'.
    d. The number of jobs in the Printer 'queue' are monitored, until the queue is empty.
    Each time the number of the jobs in the queue changes, a new 30 second TIMEOUT countdown starts.
    e. The last instance of 'Acrobat (Reader)' is then closed.

    Setting up the software to Test this file 'As Is'.
    a. Put this file 'ExcelForumPrintPdfFiles*.xlsm' in any Folder.
    b. Create the following folder if it does not exist:
    c. Extract the files from file ExcelForumPrintPdfFileDataFiles*.zip into the folder created in the step above:
    (1) NoPassword.pdf - One page dummy Pdf file that has no password.
    (2) NotPdfFile.xxx - Dummy file that is NOT a Pdf file.
    (3) PasswordABC.pdf - One page dummy Pdf file that has password of ABC.
    (4) ThreeMegabyteFile.pdf - 44 page Pdf file.
    NOTE: Original file was too big for Excelforum (had to substitute a smaller file).
    d. Open this file and go to VBA (instructions are below if you don’t know how).
    e. Find the location of the Adobe Acrobat (Reader) executable file (using Windows Explorer). A typical location is:
    c:\program files (x86)\Adobe\Acrobat Reader DC\reader\acrord32.exe
    f. At the top of code module ModPrintPdfFiles modify the value of Constant sGblAcrobatOrReaderPathAndFileNAME (If necessary).
    g. Save this file. Setup complete.

    Lewis
    Last edited by LJMetzger; 12-17-2017 at 06:36 PM.

  3. #3
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Re: Printing external PDF files based on user input

    Hi Lewis,

    I just wanted to give a big thanks to you for finding this old thread and evidently going to a considerable amount of effort to help me solve the problem. I will need to go through your solution in some detail and am bound to have some questions, but for now I just want to thank you again for your hard work.

    Andy

  4. #4
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Re: Printing external PDF files based on user input

    I have spent quite a bit of time today looking at this, but I haven't quite managed to get it working and I'm not totally confident that I have the VBA skills needed to implement it,
    despite your detailed reply and accompanying notes.

    Therefore, I hope you don't mind me asking if it would be possible for you to take a look at the attached example and maybe help me to get it working?

    Sorry to have to ask, but after all your efforts it would be a waste if it didn't get put to good use.

    Andy
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Printing external PDF files based on user input

    Hi Andy,

    I did not change any code. I just changed the constants at the top of code module ModPrintPdfFiles in your file to reflect the current positions of your data. Please let me know if you have any more problems.

    Lewis
    Attached Files Attached Files
    Last edited by LJMetzger; 12-20-2017 at 10:06 AM. Reason: Replaced file due to a 64 Bit Excel compile error

  6. #6
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Re: Printing external PDF files based on user input

    Morning Lewis,

    I have run into a Compile Error at pDevMode As DEVMODE - a screen shot is attahed for clarity.

    Andy
    Attached Images Attached Images

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Printing external PDF files based on user input

    Hi Andy,

    I apologize for your problem. It was caused by a 64 Bit Excel compile error. I included 64 bit Excel, but I do not have access to 64 bit Excel, so you are my defacto alpha tester. Please download the new file in post #5 and try again. Please let me know if you have success or failure, and hopefully we will eventually succeed.

    It might be a good idea to change your profile from office version '2016' to '64 bit 2016'.

    Lewis

  8. #8
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Re: Printing external PDF files based on user input

    Hi Lewis,

    Please see the attached screenshot. After dismissing the message, it does print the remaining maps.

    Andy
    Attached Images Attached Images

  9. #9
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Printing external PDF files based on user input

    Hi Andy,

    The good news is that 64 bit Excel is working.

    The bad news is that the error message is misleading. The screenshot looks like the sample file you posted. In the Sample file look at rows 50 and 51. There are 2 copies of 'AL1 4', but no 'AL1 1'.

    There are two error conditions that had the same error message (my mistake):
    a. 'Map Area' Name NOT FOUND in the Column 'A' (error message should have indicated that the 'Map Area' was NOT FOUND).
    b. 'File Name' Cell is BLANK (which is the message you got).

    See the attached file which corrects the error. Lines 548 thru 559 of code module ModPrintFiles contain the following changes:
    Please Login or Register  to view this content.
    Lewis
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Re: Printing external PDF files based on user input

    Hi Lewis,

    It looks to be working properly now. I am away at the moment, but I will look at it in more detail in the new year and hopefully be able to implement it.

    A huge thanks again for your input.

    Andy

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Automate printing to accept user input options
    By chasoe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2016, 12:58 AM
  2. Need help opening files based on user input
    By andreroux in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-24-2016, 10:18 PM
  3. Data Input Form with number of line items based on user input
    By j_gideon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-25-2013, 02:54 PM
  4. Moving Files based on user input to choose destination
    By kcinsti in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2012, 03:56 AM
  5. Worksheet_change issue. Change is from external source not user input.
    By beat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2012, 01:54 PM
  6. Printing External files
    By livinglegend629 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-22-2010, 04:39 PM
  7. [SOLVED] Playing .mp3 files based on user input
    By Maxi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2006, 10:35 AM

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1