borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Big Problem... Need it Solved!)Next Topic (Help Me :)) New Topic New Poll Post Reply
AndreaVB Forum : VB General : opening excel in VB
Poster Message
pwrsgal
Level: Guest


icon opening excel in VB  Archived to Disk

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
| Quote Reply
Coyote
Level: Guest

icon 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<<<

05-08-2002 at 01:15 AM
| Quote Reply
AndreaVB Forum : VB General : opening excel in VB
Previous Topic (Big Problem... Need it Solved!)Next Topic (Help Me :)) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder