+ Reply to Thread
Results 1 to 8 of 8

Macro to open external file

  1. #1
    Registered User
    Join Date
    02-02-2010
    Location
    Tasmania, Australia
    MS-Off Ver
    Excel 2007
    Posts
    36

    Macro to open external file

    Hi. I am looking to have buttons within a worksheet that the user can click and a macro will either open a website in a new default browser window (and I have this bit under control now), but I am also wanting to open other things such as MS Word, Lotus Wordpro, PDF files when a button is clicked. Is there a macro (or command) that can open ANY type of file? I have found some code for opening MS Word Doc's. Thanks in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Macro to open external file

    hello,

    you can run any .exe file using the shell command
    Please Login or Register  to view this content.
    There is also great code around the web for SHELL AND WAIT this is great when you want to open a program that will automataclly process some information (resize images for example) and the VBA code will wait on that line for the executing handle to finish its job before continuning.

    hope this helps
    cheers


  3. #3
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Macro to open external file

    duplicate post

  4. #4
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Gloucestershire
    MS-Off Ver
    Office 2010 Excel/Word/Access
    Posts
    113

    Re: Macro to open external file

    Hi,

    I rescently had a similar problem solved for me in this forumn, all the files I wished to open with the button were saved in a folder on my desktop 'ProcesSpecifications' this folder contains loads of other folders containing .doc/.pdf/.xls etc etc. please see code below:

    Please Login or Register  to view this content.
    You would have to change the line that appertains to where you want to search

    strPath = "C:\Documents and Settings\user\Desktop\ProcessSpecifications"

    you will also see the below reference:-

    strFilter = "*" & Sheets("Sheet1").Range("E17").Value & "*.*"

    the ("E17") referes to the cell number in which I type the file name or part file name of the file I wish to search for befor clicking the button to search, works brilliantly for me. I'm not a VBA enabled person and if there is any problems with the coding for you I will probably not be able to help sort. As I said, works perfectly for me,

    Good Luck,

    Andy.
    Last edited by lurchybold; 02-03-2010 at 04:53 AM.

  5. #5
    Registered User
    Join Date
    02-02-2010
    Location
    Tasmania, Australia
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Macro to open external file

    Hi and thanks to you both for your help, but I need to be more specific. I need the buttons to open 1 specific file that its targetted at and the files are in different drives and directories. Is there any simple way to have a macro to open just the one speified file, be it a .pdf, .docx or .lwp??? Thanks.

  6. #6
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Macro to open external file

    Hi,
    I think solution suggested by D_Rennie is exactly what you want. Why do you think it doesn't fit your needs?
    If you are pleased with a member's answer then use the Star icon to rate it.

  7. #7
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Macro to open external file

    though if i understand you correctly you want to give a file name say test.txt though the file can be located on diffrent dirves. well if the file is located say at ?:\Folder\Test.txt you will need to use that Dir function , ive couppled with follow hyperlink,
    Please Login or Register  to view this content.
    The code abouve could mostlikley be compressed somewhat though it gives you the idear. If this is not what you are looking for you will need to explain again as im a little slow,

    cheers

  8. #8
    Registered User
    Join Date
    02-02-2010
    Location
    Tasmania, Australia
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Macro to open external file

    My apologies to all. The solution by D_Rennie is absolutely perfect for what I am wanting to do. I am relatively new at VBA so all help is appreciated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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