PDA

Click to See Complete Forum and Search --> : Help on excel


Siddharthmark
Nov 6th, 2005, 06:20 PM
Hi,

I have written a VBA procudure in excel using Microsoft office 10.0 Object library. But I am not able to run this on other comps. since the Object library is different (11.0). I guess this is the reason for the procedure to not work. Can someone please help troubleshoot this problem. Is these a way to make this procedure compatiable across all computers irrespective of version differences?????

Thanks in advance
Siddharth

RobDog888
Nov 6th, 2005, 06:40 PM
You need to use Late Binding instead of Early Binding. Late binding does not require a reference to Excel at all allowing the use of different versions. You do need to be careful to only use properties, methods, and functions that are supported by the versions of Excel you need to support.
Option Explicit

Private Sub Form_Load()
Dim oApp as Object
Dim oWB as Object
Set oApp = CreateObject("Excel.Application")
Select Case oApp.Version
Case "10.0", "11.0", "12.0"
'Valid supported version or ???
Case Else
MsgBox "Excel Version not supported!"
'Exit your application or disable features.
End Select
Set oWB = oApp.Workbooks.Open("C:\BVook1.xls")
oWB.Sheets("Sheet1").Cells(1, 1) = "Test"
oWB.Save
oWB.Close
Set oWB = Nothing
oApp.Quit
Set oApp = Nothing

End Sub