How To Open Excel File Using Macro

Posted on the September 11th, 2008 under Excel VBA Function by Poer @ Excel VBA/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

Related Entries

External Resources

Tagged with:

3 Responses to 'How To Open Excel File Using Macro'

  1. December 16, 2008 at 4:24 am
    gary
  2. December 18, 2008 at 4:41 pm
    Poer
  3. September 1, 2009 at 7:15 pm
    Silas

Leave a Reply




XHTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
SYNTAX HIGHLIGHTER:
Place your VBA code between <pre> tags like this <pre class="brush:vb"> sub vba() ... end sub </pre>.