opening excel file in visual basic 6

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 47
Reputation: locsin is an unknown quantity at this point 
Solved Threads: 0
locsin locsin is offline Offline
Light Poster

opening excel file in visual basic 6

 
0
  #1
Sep 9th, 2007
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.
Last edited by locsin; Sep 9th, 2007 at 3:53 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 160
Reputation: kb.net is an unknown quantity at this point 
Solved Threads: 26
kb.net's Avatar
kb.net kb.net is offline Offline
Junior Poster

Re: opening excel file in visual basic 6

 
0
  #2
Sep 9th, 2007
Hi,

Use this code:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2.  
  3. Dim xl As Object
  4. Dim xlwbook As Object
  5. Dim xlsheet As Object
  6.  
  7. Set xl = CreateObject("Excel.Application")
  8. Set xlwbook = xl.Workbooks.Add
  9. Set xlsheet = xlwbook.Worksheets.Add
  10.  
  11. 'do your staff example:
  12. xlsheet.range("A1") = 100
  13. 'finish you staff
  14.  
  15. xl.Quit
  16. Set xl = Nothing
  17. Set xlwbook = Nothing
  18.  
  19. End Sub
It is never about the number of languages you know, you either have the logic of programming or you don't ...

Some of the codes I post are collected from different sites during the past couple of years, so I would like to thank them for their help and for enabling me to help.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 160
Reputation: kb.net is an unknown quantity at this point 
Solved Threads: 26
kb.net's Avatar
kb.net kb.net is offline Offline
Junior Poster

Re: opening excel file in visual basic 6

 
0
  #3
Sep 9th, 2007
Hi,

If you want to save you work just before xl.quit add:
xlwbook.saveas "c:\x.xls"
It is never about the number of languages you know, you either have the logic of programming or you don't ...

Some of the codes I post are collected from different sites during the past couple of years, so I would like to thank them for their help and for enabling me to help.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC