944,141 Members | Top Members by Rank

Ad:
Sep 9th, 2007
0

opening excel file in visual basic 6

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
locsin is offline Offline
47 posts
since Aug 2007
Sep 9th, 2007
0

Re: opening excel file in visual basic 6

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
Reputation Points: 13
Solved Threads: 29
Junior Poster
kb.net is offline Offline
169 posts
since Aug 2007
Sep 9th, 2007
0

Re: opening excel file in visual basic 6

Hi,

If you want to save you work just before xl.quit add:
xlwbook.saveas "c:\x.xls"
Reputation Points: 13
Solved Threads: 29
Junior Poster
kb.net is offline Offline
169 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: how to transparent the background of the image on PDA/Mobile Simulator (VB)
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Referencing a picture in Word 97





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC