What's wrong trying to use Excel-sample 
Author Message
 What's wrong trying to use Excel-sample

Hi!

I'm trying to run sample using VB.NET. I found this sample from site:
http://www.*-*-*.com/ ;EN-US;306022

sample is:
"Use Automation to Transfer an Array of Data to a Range on a Worksheet"

Dim oExcel As Object
        Dim oBook As Object
        Dim oSheet As Object

        'Start a new workbook in Excel.
        oExcel = CreateObject("Excel.Application")
        oBook = oExcel.Workbooks.Add

        'Create an array with 3 columns and 100 rows.
        Dim DataArray(99, 2) As Object
        Dim r As Integer
        For r = 0 To 99
            DataArray(r, 0) = "ORD" & Format(r + 1, "0000")
            DataArray(r, 1) = Rnd() * 1000
            DataArray(r, 2) = DataArray(r, 1) * 0.07
        Next

        'Add headers to the worksheet on row 1.
        oSheet = oBook.Worksheets(1)
        oSheet.Range("A1").Value = "Order ID"
        oSheet.Range("B1").Value = "Amount"
        oSheet.Range("C1").Value = "Tax"

        'Transfer the array to the worksheet starting at cell A2.
        oSheet.Range("A2").Resize(100, 3).Value = DataArray

        'Save the Workbook and quit Excel.
        oBook.SaveAs(sSampleFolder & "Book2.xls")
        oSheet = Nothing
        oBook = Nothing
        oExcel.Quit()
        oExcel = Nothing
        GC.Collect()

But when I run it, I just get error of the line:
CreateObject("Excel.Application")

Error message is:
"An unhandled exception of type 'System.Exception' occurred in
microsoft.visualbasic.dll
Additional information: Cannot create ActiveX component."

I don't have installed MS Office (using OpenOffice), should it be installed?
Anyway I downloaded OfficeXP pia's and run configuration without problems.

Then I added reference (COM-tab) called "Microsoft Office 8.0 Object
Library"

Then I added line "Imports Microsoft.Office.Interop" into my VB project, but
it's not correct according red line below it.

What's wrong with this? I think this is easy to solve, but I'm new with
VB.NET

Thanks for advance if I get any help



Sat, 15 Oct 2005 00:05:08 GMT  
 What's wrong trying to use Excel-sample

Hi!

I'm trying to run sample using VB.NET. I found this sample from site:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;306022

sample is:
"Use Automation to Transfer an Array of Data to a Range on a Worksheet"

Dim oExcel As Object
        Dim oBook As Object
        Dim oSheet As Object

        'Start a new workbook in Excel.
        oExcel = CreateObject("Excel.Application")
        oBook = oExcel.Workbooks.Add

        'Create an array with 3 columns and 100 rows.
        Dim DataArray(99, 2) As Object
        Dim r As Integer
        For r = 0 To 99
            DataArray(r, 0) = "ORD" & Format(r + 1, "0000")
            DataArray(r, 1) = Rnd() * 1000
            DataArray(r, 2) = DataArray(r, 1) * 0.07
        Next

        'Add headers to the worksheet on row 1.
        oSheet = oBook.Worksheets(1)
        oSheet.Range("A1").Value = "Order ID"
        oSheet.Range("B1").Value = "Amount"
        oSheet.Range("C1").Value = "Tax"

        'Transfer the array to the worksheet starting at cell A2.
        oSheet.Range("A2").Resize(100, 3).Value = DataArray

        'Save the Workbook and quit Excel.
        oBook.SaveAs(sSampleFolder & "Book2.xls")
        oSheet = Nothing
        oBook = Nothing
        oExcel.Quit()
        oExcel = Nothing
        GC.Collect()


But when I run it, I just get error of the line:
CreateObject("Excel.Application")

Error message is:
"An unhandled exception of type 'System.Exception' occurred in
microsoft.visualbasic.dll
Additional information: Cannot create ActiveX component."

I don't have installed MS Office (using OpenOffice), should it be installed?
Anyway I downloaded OfficeXP pia's and run configuration without problems.

Then I added reference (COM-tab) called "Microsoft Office 8.0 Object
Library"

Then I added line "Imports Microsoft.Office.Interop" into my VB project, but
it's not correct according red line below it.

What's wrong with this? I think this is easy to solve, but I'm new with
VB.NET

You cannot create an instance of an automation object unless the application is installed. In other
words, Excel must be installed.

In addition, the Imports statement is not required. Once you've added the type library to your
project the interop library should show up in the References of your project (Solution Explorer).


Microsoft MVP (Visual Basic)



Sat, 15 Oct 2005 03:02:26 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Form Resize (let's try that again without hitting the wrong key)

2. What's wrong with This Excel Code

3. What's wrong with This Excel Code

4. VB4 to Excel code - What's Wrong?

5. Here's a sample app using Outlook 2000 forms and VBA

6. Problem FTPing to MVS mainframe using Catalyst's SocketWrench Sample FTP

7. Recourse files, I think i'm using them in the wrong way

8. VB5's design interface using wrong font (or something odd)

9. Anyone tried VB sample program in Netmeeting SDK??

10. Trying to start sample: get 500.100 error

11. Trying to find sample of netuseadd

12. mapi trying to access wrong server

 

 
Powered by phpBB® Forum Software