Results 1 to 13 of 13

Thread: [RESOLVED] Excel COM issues

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    156

    Resolved [RESOLVED] Excel COM issues

    Hi there,

    this is the issue I am facing:

    I have written an app that contains a feature which exports datasets to an excel sheet and does all the little formatting things to make my users happy.
    Anyway, on my machine, I have Office 2003 installed (which means Excel COM 11.0) so everything works great.
    Unfortunately some of my target audience has Office 2000, which means Excel COM 10.0 I believe). So therein lies the problem. As soon as they try to export, error message pops up about access to protected memory etc.
    So I thought since I was using early binding, that if I change it to late binding it would work. Unfortunately ... not the case. My guess is that some methods and properties I use are not available in the 10.0 version.

    In general...How do people approach this issue? Any advice will be appreciated.
    many thanx

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Excel COM issues

    What version of VB are you using? (5, 6, .Net, VBA in an Office application,...)

    For Classic VB, the steps you need to convert to Late Binding are in a post in my Excel tutorial - I'd recommend reading it to check you haven't missed anything.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel COM issues

    Since it sounds like your already using late binding I would ask if you removed the reference to Excel 11? Excel 2000 is Excel 9.0 version.

    You need to search msdn and verify that all the functions, properties, events etc are existing in 2000 and above.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: Excel COM issues

    Quote Originally Posted by si_the_geek
    What version of VB are you using? (5, 6, .Net, VBA in an Office application,...)

    For Classic VB, the steps you need to convert to Late Binding are in a post in my Excel tutorial - I'd recommend reading it to check you haven't missed anything.

    Hey si, slightly off-topic here, don't want to hijack the thread. I followed your late-binding tutorial and it's working, but I had to change pretty much every Excel function I had because I was passing Excel objects. Y'know, had to change them from Excel.Worksheet to Object. Should I not be passing objects like that? TIA.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    156

    Re: Excel COM issues

    I'm using vb.net VS2005.
    I think Rob is right. I need to verify that all the methods and properties are found in 2000 and later, because even with late binding, if they are not available, I'll be screwed.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    156

    Re: Excel COM issues

    and yes the refs were removed :-)

  7. #7
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: Excel COM issues

    Quote Originally Posted by morpheus3230
    Hi there,

    this is the issue I am facing:

    I have written an app that contains a feature which exports datasets to an excel sheet and does all the little formatting things to make my users happy.
    Anyway, on my machine, I have Office 2003 installed (which means Excel COM 11.0) so everything works great.
    Unfortunately some of my target audience has Office 2000, which means Excel COM 10.0 I believe). So therein lies the problem. As soon as they try to export, error message pops up about access to protected memory etc.
    So I thought since I was using early binding, that if I change it to late binding it would work. Unfortunately ... not the case. My guess is that some methods and properties I use are not available in the 10.0 version.

    In general...How do people approach this issue? Any advice will be appreciated.
    many thanx
    Morph, maybe if you posted the exact code I could check it against Excel 2002, which I'm running here. The available object library for Excel on VB and VBA is 10 and 10 only.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    156

    Re: Excel COM issues

    dh, excel 2002 won't help because some of my users have excel 2000 which is 9.0 so I need to get to msdn and check the availability of some of the stuff

    however here is the code
    VB Code:
    1. Dim xlApp As Object
    2.             Dim xlBook As Object
    3.             Dim xlSheet As Object
    4.             Dim xlRange As Object
    5.  
    6.             If File.Exists("C:\Program Files\Hawkeye Customs\ECN Database\Reports\" & strJob & ".xls") Then
    7.                 File.Delete("C:\Program Files\Hawkeye Customs\ECN Database\Reports\" & strJob & ".xls")
    8.             End If
    9.  
    10.             'xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
    11.             xlApp = CreateObject("Excel.Application")
    12.             xlBook = xlApp.Workbooks.Add()
    13.             xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)
    14.             ' Place some text in the second row of the sheet.
    15.             xlSheet.Cells(1, 1) = "RUN ON"
    16.             xlSheet.Cells(1, 2) = Date.Now
    17.  
    18.  
    19.  
    20.             For intR As Integer = 0 To Me.DsecnEntriesV.Tables(0).Rows.Count - 1
    21.                 xlSheet.Cells(intR + 2, 1) = DsecnEntriesV.Tables(0).Rows(intR).Item(31)
    22.                 xlSheet.Cells(intR + 2, 2) = CType(DsecnEntriesV.Tables(0).Rows(intR).Item(28), Date).Date
    23.                 xlSheet.Cells(intR + 2, 3) = DsecnEntriesV.Tables(0).Rows(intR).Item(29)
    24.                 If Trim(UCase(DsecnEntriesV.Tables(0).Rows(intR).Item(30))) = "TRUE" Then
    25.                     xlSheet.Cells(intR + 2, 4) = "Approved"
    26.                 Else
    27.                     xlSheet.Cells(intR + 2, 4) = "Not Approved"
    28.                 End If
    29.  
    30.                 If (intR Mod 2) > 0 Then
    31.                     xlRange = xlSheet.Range("A" & (intR + 2) & ":A" & (intR + 2))
    32.                     xlRange.EntireRow.Interior.ColorIndex = 15
    33.                 End If
    34.             Next
    35.  
    36.             xlRange = xlSheet.Range("C1:C1")
    37.             xlRange.EntireColumn.ColumnWidth = 50
    38.             xlRange.EntireColumn.WrapText = True
    39.            
    40.             xlRange = xlSheet.Range("A1:d1000")
    41.             xlRange.EntireColumn.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
    42.             xlRange.EntireRow.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft
    43.             xlRange.EntireRow.Font.Size = 8
    44.  
    45.             xlRange = xlSheet.Range("A1:d1000")
    46.             xlRange.Columns.AutoFit()
    47.             'xlRange = xlSheet.Range("D1:D1")
    48.             'xlRange.Columns.AutoFit()
    49.  
    50.             xlBook.SaveAs("C:\Program Files\Hawkeye Customs\ECN Database\Reports\" & strJob & ".xls", Excel.XlFileFormat.xlWorkbookNormal)
    51.  
    52.             xlBook.Close()
    53.             xlApp.Quit()
    54.             Marshal.ReleaseComObject(xlApp)
    55.             xlApp = Nothing
    56.             MsgBox("Finished Excel Export!", MsgBoxStyle.Information, "ECN")

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    156

    Re: Excel COM issues

    Rob, is there an easy way to verify the existance of methods and properties in an Excel version on MSDN. I'm not even sure how and where to start?
    thanx

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Excel COM issues

    Assuming that DsecnEntriesV is not Excel related (I'm guessing it's the source of the data), it all looks like fairly basic stuff - and should be supported by Excel 97 upwards.

    The only thing that concerns me is the constants, eg: Excel.XlHAlign.xlHAlignLeft
    I don't use VB.Net, but these bits look early bound to me.

    Quote Originally Posted by disruptivehair
    Hey si, slightly off-topic here, don't want to hijack the thread. I followed your late-binding tutorial and it's working, but I had to change pretty much every Excel function I had because I was passing Excel objects. Y'know, had to change them from Excel.Worksheet to Object. Should I not be passing objects like that? TIA.
    When using Late Binding in Classic VB (and possibly .Net), you cannot use Excel.Anything in your code, so you should use Object the data type instead. If you want me to check your code, create a new thread and PM me a link to it.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel COM issues

    According to this initial line I believe your reference is still added. You should be getting a Cast error of "Excel.Worksheet" is not defined.

    xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)

    Did you also remove any "Imports" for Excel at the top of your class?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    156

    Re: Excel COM issues

    I did not :-(
    I will try it again.
    As far as the line you quoted goes...how do I rewrite that so that it works with late binding?
    Thanx

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    156

    Re: Excel COM issues

    just for the record... I have removed all instances of the early binding and replaced it with late and changed all the references to any excel properties to corresponding integer values and life is good now.
    Everything is working great on excel 2000 and later, so I am good.
    Many thanx to all

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width