How To Open Excel File Using Macro

Imagine this condition; We are in the middle of doing something using Excel VBA macro, then we want the macro to automatically show the File Open dialog box to make us (user) able to choose another Excel file to be opened by Excel.

Got the picture? Below is vba procedure that do exactly like that, show the File Open dialog box, and open the Excel file selected by user.

Sub OpenExcelFile()

    Dim vFile As Variant

    'Showing Excel Open Dialog Form
    vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _
    "*.xl*", 1, "Select Excel File", "Open", False)

    'If Cancel then exit
    If TypeName(vFile) = "Boolean" Then
        Exit Sub
    End If

    'Open selected file
    Workbooks.Open vFile

End Sub
This entry was posted in Excel VBA Function and tagged , , , , , , , , , , , , , . Bookmark the permalink.

16 Responses to How To Open Excel File Using Macro

  1. gary says:

    Thanks this works great. Is there also way to have the macro open a specfic xls file?

  2. Poer says:

    Hi Gary, if you just wanna open specific xl file, you can directly use workbooks.open “c:\xlfilename.xls” function.

  3. Silas says:

    Is there an easy way to open a non-excel file, based on the contents of the cell in an excel file.

    For example, if i have a file

    DP1253 – 50393.tif, can I open it automatically on a macro run if i have a cell (say A1) with a value DP1253

    Thanks in advance

  4. Elena says:

    Hey I have a text file that I need to open with excel VBA macro creating loop. Each word will have to be placed in individual cells of the excel sheet.
    Can anyone help?

  5. hello friends , there is a window already opened at desktop , i usually control this window by keyboard,,,,like i type some numbers by keyboard on this window and then press enter and then i got the result.I want to make an excel macro which will automatically go to this opened window and then wil press the required number(like 1 , 2 and enter) and then i get get the result automatically , is this possible.Plz tell.

    thanks in advance

  6. Rick8948 says:

    I have read dozens of answers about opening another Excel file from a VBA macro, but none answer my problem. Here it is: I have a macro that runs perfectly (opens a file, processes the data, etc.) as long as I invoke the macro from the Macro window displayed by Alt-F8 or Tools->Macro->Macros. However, if I invoke the macro by a shortcut key, i.e., Ctl-Shift-U, the code following the Workbooks.Open statement never gets executed. Is this a bug in Excel, Windows, etc.? The same thing happens with Excel 2003 on Windows XP and with Excel 2007 on Windows 7.

  7. Justdream says:

    Thanks a lot, could you please share how we could create macro to open Excel file in the same existing excel sheet that contains macro source..

  8. Pingback: Prestashop Templates

  9. Pingback: Graphics Work

  10. Pingback: debt consolidation companies

  11. Pingback: reverse mortgages calculator

  12. Pingback: debt consolidation companies

  13. Pingback: financial freedom reverse mortgage

  14. Pingback: watch Superbowl online

  15. Pingback: super bowl 2012

  16. Pingback: ares free download

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>