|
-
Jun 27th, 2003, 08:46 PM
#1
Thread Starter
New Member
Excel Object Error
Here is the code:
1 Dim exExcel As Excel.Application
2 Dim exWorkbook As Excel.Workbook
3 Dim exSheet As Excel.Worksheet
5 exExcel = New Excel.Application
6 exWorkbook = exExcel.Workbooks.Open(strFilename)
7 exSheet = exWorkbook.Worksheets("Sheet1")
I get an error at line 6 saying:
---------------------------------------------------------------------------
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Program.exe
Additional information: The server threw an exception.
---------------------------------------------------------------------------
Now I know the file exists, and all dll's are loaded. Why am I coming up with this error?
Just in case, it might help to know that I am running under the NET framework, not vb6. I am using Excel 8.0 Object Library
If you own a Compaq, throw it out. They are ghay!
-
Jun 30th, 2003, 12:18 AM
#2
Hyperactive Member
i dont know about how u do this in NET framework
but in vb you should use the SET keyword to reference an object
Code:
Dim exExcel As Excel.Application
Dim exWorkbook As Excel.Workbook
Dim exSheet As Excel.Worksheet
Set exExcel = New Excel.Application
Set exWorkbook = exExcel.Workbooks.Open(strFilename)
Set exSheet = exWorkbook.Worksheets("Sheet1")
-
Jun 30th, 2003, 12:37 PM
#3
Thread Starter
New Member
Solved!
Actually I solved the problem myself, but I had to do quite a bit of searching to get it. Here is the update code:
Option Strict Off
Public Shared xlApp As Object
Public Shared xlBook As Object
Public Shared xlSheet As Object
xlApp = CreateObject("Excel.Application")
'Late bind an instance of an Excel workbook.
xlBook = xlApp.Workbooks.Add
'Late bind an instance of an Excel worksheet.
xlSheet = xlBook.Worksheets(1)
xlSheet.Activate()
xlBook.SaveAs(strFilename)
If you own a Compaq, throw it out. They are ghay!
-
Aug 23rd, 2003, 04:17 AM
#4
Hyperactive Member
Option Strict Off
Public Shared xlApp As Object
Public Shared xlBook As Object
Public Shared xlSheet As Object
xlApp = CreateObject("Excel.Application")
'Late bind an instance of an Excel workbook.
xlBook = xlApp.Workbooks.Add
'Late bind an instance of an Excel worksheet.
xlSheet = xlBook.Worksheets(1)
xlSheet.Activate()
xlBook.SaveAs(strFilename)
your code for VB6 or .Net I never use Shared statement
Don't leave it till tomorrow, Do It Now!
5361726176757468204368616E63686F747361746869656E

-
Aug 23rd, 2003, 12:58 PM
#5
Thread Starter
New Member
i don't see the point of not using shared, whats so bad about it?
If you own a Compaq, throw it out. They are ghay!
-
Aug 25th, 2003, 09:29 PM
#6
Hyperactive Member
Sorry for my english.. 
I mean, I don't know about Shared statement. It's used for VB6 or VB.Net.
I have same problem with u, how to solve please?
Don't leave it till tomorrow, Do It Now!
5361726176757468204368616E63686F747361746869656E

-
Aug 26th, 2003, 11:22 AM
#7
Thread Starter
New Member
The .NET code looks like this:
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFilename & ";" & _
"Extended Properties=Excel 8.0;"
'Excel Sheet Name as TableName (Make sure where Sheet1 appears that you change the name to your sheet name)
xlOleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
xlOleDbDataAdapter.Fill(DataForm.xlData, "Sheet1")
xlGrid.DataSource = DataForm.xlData.Tables(0).DefaultView
If you own a Compaq, throw it out. They are ghay!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|