+ Reply to Thread
Results 1 to 10 of 10

Opening PDF file via code

  1. #1
    Registered User
    Join Date
    09-08-2014
    Location
    -
    MS-Off Ver
    -
    Posts
    68

    Opening PDF file via code

    Hello!
    I have a program which outputs a report as a PDF file.
    I've got the outputting working, but how can I make it open the PDF afterwards?
    The PDF file name and path is a variable called filepath (it's generated as part of the code - i.e. filepath = C:\User\Documents\...\file.pdf)
    Any help?

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Opening PDF file via code

    Please Login or Register  to view this content.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    09-08-2014
    Location
    -
    MS-Off Ver
    -
    Posts
    68

    Re: Opening PDF file via code

    Hey nathansav,
    I'm worried about this tool being used on a computer with a different pdf reader, version, filepath whatever...does it have to be referenced? Is there no way to make it use the operating system's default program?

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Opening PDF file via code

    Yes, but you'll need to look at that. You need to look at Special Folders in VBA, getting the version of the PDF reader thats a bit trickier, i'd error trap opening the alternatives,

    so reader 1
    error try reader 2
    error try reader 3
    no error

  5. #5
    Registered User
    Join Date
    09-08-2014
    Location
    -
    MS-Off Ver
    -
    Posts
    68

    Re: Opening PDF file via code

    Eurgh, sounds complicated. I think I'll just have a MsgBox("Your report can be found at " & filepath). Lazy, but easy. XD
    Actually is there a way I can make it open a folder? Because I could at least make it open the folder with the report in it...

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Opening PDF file via code

    Look at Shell() this will help with what you want.

    Shell "C:WindowsExplorer.exe", vbNormalFocus

  7. #7
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Opening PDF file via code

    Look at Shell() this will help with what you want.

    Shell "C:WindowsExplorer.exe", vbNormalFocus

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,977

    Re: Opening PDF file via code

    I'd use an API call:
    At the top of your module:
    Please Login or Register  to view this content.
    New routine:
    Please Login or Register  to view this content.
    So now your code can simply use:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Opening PDF file via code

    Please Login or Register  to view this content.
    Will pretty much open anything with the default fileviewer

  10. #10
    Registered User
    Join Date
    09-08-2014
    Location
    -
    MS-Off Ver
    -
    Posts
    68

    Re: Opening PDF file via code

    Kyle123 and romperstomper's solutions were brill :D Thanks
    Kyle's does come up with an excel warning box thingymabob about potential harm to the computer so I'm going with Romper's.

+ 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] VBA code for opening a file with a variable version number in the file name
    By trishcollins in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-04-2014, 04:38 PM
  2. [SOLVED] VB Code to copy without opening the file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-05-2013, 08:24 PM
  3. [SOLVED] Error in code - play music file automatically after opening file
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-15-2013, 10:06 AM
  4. [SOLVED] VBA-code for opening a file max x times
    By Saturn in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-03-2013, 09:43 AM
  5. [SOLVED] Code for opening file if match with file name is found
    By cokillerliu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-25-2013, 08:41 PM

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