# Simple VB6 code to open an Excel file



## glockster

I need very simple code in VB6 that allows the click of a VB6 CommandButton to open an Excel file on the C:\ drive named "Counselor".

Thanks for any help!


----------



## Andrew Fergus

Hi

Try this:


		Code:
__


Private Sub Command1_Click()

On Error GoTo ErrHandler
    Dim xlApp As Object
    Dim xlWB As Object
    
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = True
    
    Set xlWB = xlApp.Workbooks.Open("c:\Counselor.xls")
    Exit Sub
    
ErrHandler:
    MsgBox "There is a problem opening that workbook!", vbCritical, "Error!"
    
End Sub


HTH, Andrew


----------



## vinke

Hi Andrew,

I am writing a project and need to export the Ms-Access Database to Ms-Excel to enable the user print it using Ms-Excel. Can you please help me out.

Thanks and remain blessed.


----------

