Simple VB6 code to open an Excel file

glockster

Board Regular
Joined
Mar 24, 2002
Messages
181
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!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,225,669
Messages
6,186,348
Members
453,350
Latest member
mjohnston819

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top