954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

opening excel file in visual basic 6

I try to open excel file in visual basic 6. Somebody gave me this code to open excel file. But when i create a my new form and type this code. An error occured for this code

Private Sub Form_Load()
Dim x_app As Excel.Application
Dim x_wbk As Excel.Workbook
Dim x_wsh As Excel.Worksheet

Set x_app = New Excel.Application
Set x_wbk = x_app.Workbooks.Add
Set x_wsh = x_wbk.Worksheets.Add

x_wsh.Cells(1, 1) = 50
x_app.Visible = True

End Sub

When I declare

Dim x_app as Excel.Application in my new form it is not accepted It change to Dim x_app as Excelfrm.

How to add Excel in my object browser. Maybe it is the solution to open my excel file in visual basic 6.

Anybody can help me and I appreaciate it alot. Step by step instruction to clearly open excel file in vb6 is served me best.

Thank you in advance.

locsin
Light Poster
47 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

Hi,

Use this code:

Private Sub Command1_Click()

Dim xl As Object
Dim xlwbook As Object
Dim xlsheet As Object

    Set xl = CreateObject("Excel.Application")
    Set xlwbook = xl.Workbooks.Add
    Set xlsheet = xlwbook.Worksheets.Add
    
    'do your staff example:
    xlsheet.range("A1") = 100
    'finish you staff
    
    xl.Quit
    Set xl = Nothing
    Set xlwbook = Nothing

End Sub
kb.net
Junior Poster
172 posts since Aug 2007
Reputation Points: 13
Solved Threads: 29
 

Hi,

If you want to save you work just before xl.quit add:
xlwbook.saveas "c:\x.xls"

kb.net
Junior Poster
172 posts since Aug 2007
Reputation Points: 13
Solved Threads: 29
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You