?
Solved

Using Excel with VB.NET give message 32792

Posted on 2005-03-11
7
Medium Priority
?
698 Views
Last Modified: 2010-08-05
This code gives me a strange message. I have done similar thing without problem on VB6. Why is it a problem in VB.NET. I attached COM Library 1.4 "Microsoft Excel 10.0". However every time I go back the reference disappeard again. It seems I do somehting very basic wrong here.

        Dim filename As String
        Dim objExcel As New Excel.Application
        Dim objWrkBk As Excel.Workbook
        Dim objSht As Excel.Worksheet
        filename = "C:\dwgexcl"
        On Error Resume Next

        objWrkBk = objExcel.Workbooks.Open(filename)
        Debug.WriteLine(Err.Number) ' writes 32792
        Debug.WriteLine(Err.Description) ' Geting a german message on my german XP translated meaning "Old format or wrong type library"
        objSht = objWrkBk.Worksheets(1)
        objSht.PrintOut()
        objExcel.Quit()
0
Comment
Question by:HolliStt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13522321
Im not sure about your errors... but I've rewritten your code slightly (although I'm doing this straight here i.e. not tested):

        Dim proceed As Boolean = True
        Dim filename As String
        Dim objExcel As New Excel.Application
        Dim objWrkBk As Excel.Workbook
        Dim objSht As Excel.Worksheet

        filename = "C:\dwgexcl"

        If IO.File.Exists(filename) Then
            Try
                objWrkBk = objExcel.Workbooks.Open(filename)
            Catch ex As Exception
                Msgbox (ex.Message)
                Proceed = False
            End Try

            If Proceed Then
                Try
                    objSht = objWrkBk.Worksheets(1)
                    objSht.PrintOut()
                Catch ex2 As Exception
                    Msgbox(ex2.Message)
                End Try

               objExcel.Quit()
            End If
         End If

============

This may not fix your problem, but I think it should isolate any errors better at least
0
 
LVL 1

Author Comment

by:HolliStt
ID: 13522379
Thanks that was very nice. It indeed does not handle the problem. I exhumed my VB6 and tried the following and it works with no problem. Just to prove it. I must admit I have no VB.NET experience. I was on Java and C++ in between. So I have the feeling this is something very very fundamental. Basically. I am saying that I would like to get the bolow code running on VB.NET. Above code from you gets me the already mentioned message. So something is wrong in the connecting of VB.NET with Excel.

    Dim filename As String
    Dim objExcel As New Excel.Application
    filename = "C:\dwgexcl"

    objExcel.Workbooks.Open (filename)
    objExcel.ActivePrinter = "VirtualCreator on Ne01:"
    objExcel.Worksheets(1).PrintOut
    objExcel.Quit

Regards,
Jürgen
0
 
LVL 12

Accepted Solution

by:
S-Twilley earned 250 total points
ID: 13522419
Ok, i just tested this code (basically same as above) with an excel workbook i just created using MS Office XP:


Imports Excel
Module modExcel
    Sub PrintWorksheet(ByVal Filename As String, ByVal SheetNumber As Integer)
        Dim proceed As Boolean = True

        Dim objExcel As New Excel.Application()
        Dim objWrkBk As Excel.Workbook
        Dim objSht As Excel.Worksheet

        If IO.File.Exists(Filename) Then
            Try
                objWrkBk = objExcel.Workbooks.Open(Filename)
            Catch ex As Exception
                MsgBox(ex.Message)
                proceed = False
            End Try

            If proceed Then
                Try
                    objSht = objWrkBk.Worksheets(SheetNumber)
                    'objSht.PrintOut()
                Catch ex2 As Exception
                    MsgBox(ex2.Message)
                End Try

                objExcel.Quit()
            End If
        End If
    End Sub
End Module


=========

Ok, so i didnt print it out, but no errors were raised.
Just to check, I selected the reference to the "Microsoft Excel 10.0 Object Library" in Solution Explorer... and it's version number is 1.4

I'd say that if the above doesn't work with your workbook... that the work book might be in an old format? or corrupt?   or that your excel library is causing the problems.


=========
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:S-Twilley
ID: 13522421
Sorry... I assumed the code was self explanitory... but to call it in your case:

PrintWorksheet("C:\dwgexcl",1)
0
 
LVL 1

Author Comment

by:HolliStt
ID: 13522464
I found the problem. I am using a German XP (and VB.NET) but have a English Office XP installed. That does not work. Except one does temporarily change the Culture Info. The following worked:

        Dim proceed As Boolean = True
        Dim filename As String
        Dim objExcel As New Excel.Application
        Dim objWrkBk As Excel.Workbook
        Dim objSht As Excel.Worksheet
        Dim thisThread As System.Threading.Thread = _
            System.Threading.Thread.CurrentThread
        Dim originalCulture As System.Globalization.CultureInfo = _
            thisThread.CurrentCulture
        Dim tempExpense As Object
        Dim tempIncome As Object
        filename = "C:\dwgexcl.xls"
        Try
            thisThread.CurrentCulture = New System.Globalization.CultureInfo( _
                "en-US")

        If IO.File.Exists(filename) Then
            Try
                objWrkBk = objExcel.Workbooks.Open(filename)
            Catch ex As Exception
                MsgBox(ex.Message)
                proceed = False
            End Try

            If proceed Then
                Try
                        objSht = objWrkBk.Worksheets(1)
                    objSht.PrintOut()
                Catch ex2 As Exception
                    MsgBox(ex2.Message)
                End Try

                objExcel.Quit()
            End If
        End If

        Finally
            ' Restore the culture information for the thread after the
            ' Excel calls have completed.
            thisThread.CurrentCulture = originalCulture

        End Try

Link in German where it got all explained:

http://msdn.microsoft.com/library/deu/default.asp?url=/library/DEU/dv_wrcore/html/wrconglobalizinglocalizingofficesolutions.asp

Don't know how to find the English version.

Thanks anyhow.

Regards
Jürgen
0
 
LVL 1

Author Comment

by:HolliStt
ID: 13522469
I give you the points because you helped me translating my coding into standard VB.NET.
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13522472
Thanks... glad I could help, even just a little
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question