ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Object Library problem (https://www.excelbanter.com/excel-programming/374218-object-library-problem.html)

djExcel

Object Library problem
 
Problem is like this: I've made a system, where one user fills in the title
area of a worksheet and system sends an e-mail to selected user. After that
the other user fills in the rest of the worksheet and press 'Ready'-button,
which sends again an e-mail to the user, who originally filled in the title
area. System works ok, but if these two users have different version of Excel
(e.g. 2000 and 2003), then the newer version changes the version of Microsoft
Outlook Object Library (Tools / References in Visual Basic Editor) and after
that the older version can't open the file (gives an error message). Is it
possible to set appropriate version of Object Library programmatically
instead of choosing Tools / References command in Visual Basic Editor and
selecting Object Library there?

Jim Thomlinson

Object Library problem
 
Sounds like you are using early binding (adding the reference at design time
instead of run time). Change to late binding something like this...

dim appOutLook as object

set appOutLook = CreateObject("OutLook.Application")

Now you are not hooked into any specific version of OutLook...
--
HTH...

Jim Thomlinson


"djExcel" wrote:

Problem is like this: I've made a system, where one user fills in the title
area of a worksheet and system sends an e-mail to selected user. After that
the other user fills in the rest of the worksheet and press 'Ready'-button,
which sends again an e-mail to the user, who originally filled in the title
area. System works ok, but if these two users have different version of Excel
(e.g. 2000 and 2003), then the newer version changes the version of Microsoft
Outlook Object Library (Tools / References in Visual Basic Editor) and after
that the older version can't open the file (gives an error message). Is it
possible to set appropriate version of Object Library programmatically
instead of choosing Tools / References command in Visual Basic Editor and
selecting Object Library there?


djExcel

Object Library problem
 
Thank You for Your answer.

Now I'm using code like this, and it's working:

Sub DoMail(MailAddress As String)
Dim AppMail As Object
Set AppMail = CreateObject("OutLook.Application")
With AppMail.CreateItem(olMailItem)
.To = MailAddress
.Subject = "Work is ready"
.Body = "Check the worksheet for results."
.Send
End With
Set AppMail = Nothing
End Sub

Is this same kind of technique possible when using ADO connection to SQL
Server? Here is a sample code that I'm currently using (which requires me to
select Microsoft ActiveX Data Objects Library in advance (Tools /
References)):

Public cnADO As ADODB.Connection
Public Rs1 As ADODB.Recordset
Public strConn As String

Sub DoConnection()
Set cnADO = New ADODB.Connection
strConn = "provider=sqloledb;" & _
"data source=xxx;" & _
"initial catalog=xxx;" & _
"user id=xxx;" & _
"password=xxx;"
cnADO.Open strConn
End Sub

Sub Main_program()
DoConnection
Set Rs1 = New ADODB.Recordset
Rs1.ActiveConnection = cnADO
Rs1.Open "SELECT * FROM ..."
...
End Sub

Bob Phillips

Object Library problem
 

"djExcel" wrote in message
...
Thank You for Your answer.

Now I'm using code like this, and it's working:

Sub DoMail(MailAddress As String)
Dim AppMail As Object
Set AppMail = CreateObject("OutLook.Application")
With AppMail.CreateItem(olMailItem)
.To = MailAddress
.Subject = "Work is ready"
.Body = "Check the worksheet for results."
.Send
End With
Set AppMail = Nothing
End Sub



You c an't use olMailItem as that is an Outlook constant in the Outlook type
library.

Use

With AppMail.CreateItem(0)


Is this same kind of technique possible when using ADO connection to SQL
Server? Here is a sample code that I'm currently using (which requires me

to
select Microsoft ActiveX Data Objects Library in advance (Tools /
References)):

Public cnADO As ADODB.Connection
Public Rs1 As ADODB.Recordset
Public strConn As String

Sub DoConnection()
Set cnADO = New ADODB.Connection
strConn = "provider=sqloledb;" & _
"data source=xxx;" & _
"initial catalog=xxx;" & _
"user id=xxx;" & _
"password=xxx;"
cnADO.Open strConn
End Sub

Sub Main_program()
DoConnection
Set Rs1 = New ADODB.Recordset
Rs1.ActiveConnection = cnADO
Rs1.Open "SELECT * FROM ..."
...
End Sub



Sub DoConnection()
Set cnADO = CreateObject("ADODB.Connection")
strConn = "provider=sqloledb;" & _
"data source=xxx;" & _
"initial catalog=xxx;" & _
"user id=xxx;" & _
"password=xxx;"
cnADO.Open strConn
End Sub

Sub Main_program()
DoConnection
Set Rs1 = CreateObject("ADODB.Recordset")
Rs1.ActiveConnection = cnADO
Rs1.Open "SELECT * FROM ..."
...
End Sub




djExcel

Object Library problem
 
Thank You. Now I got the idea.


All times are GMT +1. The time now is 03:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com