|
-
Oct 16th, 2006, 04:19 PM
#1
Thread Starter
Addicted Member
[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
-
Oct 16th, 2006, 05:55 PM
#2
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.
-
Oct 17th, 2006, 01:04 AM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 17th, 2006, 05:36 AM
#4
Hyperactive Member
Re: Excel COM issues
 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.
-
Oct 17th, 2006, 08:09 AM
#5
Thread Starter
Addicted Member
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.
-
Oct 17th, 2006, 08:23 AM
#6
Thread Starter
Addicted Member
Re: Excel COM issues
and yes the refs were removed :-)
-
Oct 17th, 2006, 09:25 AM
#7
Hyperactive Member
Re: Excel COM issues
 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.
-
Oct 17th, 2006, 09:39 AM
#8
Thread Starter
Addicted Member
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:
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object
Dim xlRange As Object
If File.Exists("C:\Program Files\Hawkeye Customs\ECN Database\Reports\" & strJob & ".xls") Then
File.Delete("C:\Program Files\Hawkeye Customs\ECN Database\Reports\" & strJob & ".xls")
End If
'xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.Add()
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)
' Place some text in the second row of the sheet.
xlSheet.Cells(1, 1) = "RUN ON"
xlSheet.Cells(1, 2) = Date.Now
For intR As Integer = 0 To Me.DsecnEntriesV.Tables(0).Rows.Count - 1
xlSheet.Cells(intR + 2, 1) = DsecnEntriesV.Tables(0).Rows(intR).Item(31)
xlSheet.Cells(intR + 2, 2) = CType(DsecnEntriesV.Tables(0).Rows(intR).Item(28), Date).Date
xlSheet.Cells(intR + 2, 3) = DsecnEntriesV.Tables(0).Rows(intR).Item(29)
If Trim(UCase(DsecnEntriesV.Tables(0).Rows(intR).Item(30))) = "TRUE" Then
xlSheet.Cells(intR + 2, 4) = "Approved"
Else
xlSheet.Cells(intR + 2, 4) = "Not Approved"
End If
If (intR Mod 2) > 0 Then
xlRange = xlSheet.Range("A" & (intR + 2) & ":A" & (intR + 2))
xlRange.EntireRow.Interior.ColorIndex = 15
End If
Next
xlRange = xlSheet.Range("C1:C1")
xlRange.EntireColumn.ColumnWidth = 50
xlRange.EntireColumn.WrapText = True
xlRange = xlSheet.Range("A1:d1000")
xlRange.EntireColumn.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
xlRange.EntireRow.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft
xlRange.EntireRow.Font.Size = 8
xlRange = xlSheet.Range("A1:d1000")
xlRange.Columns.AutoFit()
'xlRange = xlSheet.Range("D1:D1")
'xlRange.Columns.AutoFit()
xlBook.SaveAs("C:\Program Files\Hawkeye Customs\ECN Database\Reports\" & strJob & ".xls", Excel.XlFileFormat.xlWorkbookNormal)
xlBook.Close()
xlApp.Quit()
Marshal.ReleaseComObject(xlApp)
xlApp = Nothing
MsgBox("Finished Excel Export!", MsgBoxStyle.Information, "ECN")
-
Oct 17th, 2006, 09:53 AM
#9
Thread Starter
Addicted Member
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
-
Oct 17th, 2006, 11:54 AM
#10
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.
 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.
-
Oct 17th, 2006, 12:11 PM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 17th, 2006, 12:53 PM
#12
Thread Starter
Addicted Member
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
-
Oct 17th, 2006, 03:58 PM
#13
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|