Opening Worksheets in vb excel components!!

MidWaYz
03-09-2003, 05:00 AM
Hi, I'm currrently working upon a vb program with office components, but I cant open any worksheets with the excel components throught the commondialog!

Please need help.

Thank you for your kind consideration.

Mid

Flyguy
03-09-2003, 12:56 PM
You have to be more specific about what you want to do and how you are doing it.

MidWaYz
03-11-2003, 10:13 PM
You have to be more specific about what you want to do and how you are doing it.

Ok.. I'm a newbie to vb and I'm quite lost in all these things which I try learning by myself. I just add the office xp web components to the project and with the following coding on form load:

commondialog1.dialogtitle = "Open"
commondialog1.filter = "*.xls"
commondialog1.showopen

spreadsheet1.datasource = commondialog1.filename

With the coding, I did hope that it would open one spreadsheets already created with ms excel, but to my surprise nothing happen. Could it be cuz the excel components only do import xml data?

Please help.

Thank you for your kind consideration.

Samadhi
03-12-2003, 10:57 AM
Well, I pretty much just use VB in Access but it should be similar. Here is how I open my excel documents when I need to import/export data or whatever.

Private Sub Open_Excel()
Dim dB As Database, objExcel As Object, strFileName As String,_
shtWorksheet As Excel.Worksheet

strFileName = "C:\excelfile.xls"

Set dB = CurrentDb()
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open (strFileName) 'This opens the workbook
'This allows you to set a variable to the sheet you want to work on
Set shtWorksheet = objExcel.Workbooks("excelfile").Worksheets_
("Sheet1")

End Sub

MidWaYz
03-13-2003, 07:15 AM
Well, I pretty much just use VB in Access but it should be similar. Here is how I open my excel documents when I need to import/export data or whatever.

Private Sub Open_Excel()
Dim dB As Database, objExcel As Object, strFileName As String,_
shtWorksheet As Excel.Worksheet

strFileName = "C:\excelfile.xls"

Set dB = CurrentDb()
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open (strFileName) 'This opens the workbook
'This allows you to set a variable to the sheet you want to work on
Set shtWorksheet = objExcel.Workbooks("excelfile").Worksheets_
("Sheet1")

End Sub



Well, I'm using the components with the ms office xp web components instead of the reference. Infact I'm trying to make a read only excels with vb but instead importing the spreadsheets it just show me the open dialog and choose the file and when I click open, nothing appears within the excel component!

Please help!!

Samadi, I did try yours but didnt work.. thnx for the help anyway.

Please anybody want to help a poor newbie!! :P

LOL Thnx everybody!!

MidWaYz
03-13-2003, 07:23 AM
Oh...!! In fact, can I import a spreadsheets in the office xp excel components as it is, just to display it as a view only application? That's my real goal... but seems I've got everything wrong from my coding above!!

Thnx providing helps!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum