Late binding question
-
I am trying to rid myself of the problem of different version being used for excel on my customers machines. I have several programs the have a feature that allows the data sets to be save into excel. Using the interop and early binding gives me a problem with the office version, on the users machine. So I know to fix this I should use late binding. I don't really understand how to do this. I understand the concept, but can't quite get the method of execution right. Here is an example of my code: Private Sub createSpreadSheet() Dim EXL As Object Dim wsheet As New Worksheet Dim da As New SqlDataAdapter EXL = CreateObject("excel.application") wsheet = EXL.Workbooks.Add.Worksheets.Add wsheet = EXL.Workbooks.Item(1).Worksheets("Sheet1") Dim str1 As String Dim intCount As Integer intCount = Label57.Text - 1 Dim checkHeader As String Dim I As Integer For I = 0 To 5 checkHeader = strHead(I) Select Case checkHeader Case "wo_num" strHead(I) = "Work Order" strCwidth(I) = 100 Case "status_description" strHead(I) = "Status" strCwidth(I) = 100 Case "priority_description" strHead(I) = "Priorty" strCwidth(I) = 100 Case "category_description" strHead(I) = "Category" strCwidth(I) = 100 Case "location_description" strHead(I) = "Location" strCwidth(I) = 130 Case "wo_user" strHead(I) = "Requested By" strCwidth(I) = 130 Case "wo_in_date" strHead(I) = "Date Entered" strCwidth(I) = 130 Case "wo_date_needed" strHead(I) = "Date Needed" strCwidth(I) = 130 Case "wo_fixed_date" strHead(I) = "Date Repaired" strCwidth(I) = 140 Case "wo_description" strHead(I) = "Description" strCwidth(I) = 560 Case "wo_detailed_location" strHead(I) = "Detailed Location" strCwidth(I) = 330 Case "wo_est_time" strHead(I) = "Est. Time"
-
I am trying to rid myself of the problem of different version being used for excel on my customers machines. I have several programs the have a feature that allows the data sets to be save into excel. Using the interop and early binding gives me a problem with the office version, on the users machine. So I know to fix this I should use late binding. I don't really understand how to do this. I understand the concept, but can't quite get the method of execution right. Here is an example of my code: Private Sub createSpreadSheet() Dim EXL As Object Dim wsheet As New Worksheet Dim da As New SqlDataAdapter EXL = CreateObject("excel.application") wsheet = EXL.Workbooks.Add.Worksheets.Add wsheet = EXL.Workbooks.Item(1).Worksheets("Sheet1") Dim str1 As String Dim intCount As Integer intCount = Label57.Text - 1 Dim checkHeader As String Dim I As Integer For I = 0 To 5 checkHeader = strHead(I) Select Case checkHeader Case "wo_num" strHead(I) = "Work Order" strCwidth(I) = 100 Case "status_description" strHead(I) = "Status" strCwidth(I) = 100 Case "priority_description" strHead(I) = "Priorty" strCwidth(I) = 100 Case "category_description" strHead(I) = "Category" strCwidth(I) = 100 Case "location_description" strHead(I) = "Location" strCwidth(I) = 130 Case "wo_user" strHead(I) = "Requested By" strCwidth(I) = 130 Case "wo_in_date" strHead(I) = "Date Entered" strCwidth(I) = 130 Case "wo_date_needed" strHead(I) = "Date Needed" strCwidth(I) = 130 Case "wo_fixed_date" strHead(I) = "Date Repaired" strCwidth(I) = 140 Case "wo_description" strHead(I) = "Description" strCwidth(I) = 560 Case "wo_detailed_location" strHead(I) = "Detailed Location" strCwidth(I) = 330 Case "wo_est_time" strHead(I) = "Est. Time"
I don't do Office Interop, but I seem to remember something about using the lowest Primary Interop Assemblies, like Office 2000, and they'll work with the higher versions of Office, so long as you don't want to use any of the new functionality that those versions offer. For example, write your application using the Office 2000 PIA's and it should work with Office 2000, XP, and 2003. I could be wrong though.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007