Please HELP!!!! I am trying to open Excel 2000 through a Visual Basic Program. I've been able to open Word2000 but I can not open Excel2000. What my program is SUPPOSE to be doing is......having the user choose a directory a file for which the spreadsheet they want it located, and then I want excel to open that spreadsheet that the user chose....it won't work,
Can someone please help??
31-07-2002 at 07:22 PM
|
Coyote Level: Guest
Re: opening excel in VB Archived to Disk
This should resolve the problem.
To test this.
If you like create a Test.xls file or use an existing file.
Open a new project.
Make a reference to "Microsoft Excel 9.0 Object Library"
Then add a command button to the form.
Copy and paste the following code behind your form.
AND - Edit the code to the path of the XLS file your testing with.
' ****** CODE STARTS HERE ********
Option Explicit
Public Function openExcelFile()
Dim EFile As String
' EDIT the next line to the path/string that your user selects
EFile = "C:CodeNewAtemp2zipExcel2test.xls"
Dim msExcelApp As Object
Dim msExcelWorkbook As Object
Dim xlWs As Object
Set msExcelApp = GetObject("", "Excel.Application")
msExcelApp.Visible = True
msExcelApp.UserControl = True
' Assumes No password - code changes if so.
Set msExcelWorkbook = Excel.Workbooks.Open(EFile)
Set msExcelWorkbook = Nothing
Set msExcelApp = Nothing
'Set msExcelWorksheet = Nothing
End Function
Private Sub Command1_Click()
openExcelFile
End Sub
' ***** CODE ENDS HERE *****
This will open Excel and the XLS file you specify. That winkie icon in the code should be a close parenthese -shift+0
Hope this helps...
Take Care..
>>>Coyote<<<