Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Adding a reference programatically

I create a new workbook simply by copying a worksheet, i.e.
ActiveSheet.copy.
The problen is that the sheet has subroutines that require the ADODB and so
the new workbook needs to reference the Microsoft ActiveX Data Objects
Library.
I know I can add that reference to the new workbook using Tools:References
from the main menu but how can I add that reference to the new workbook
programmatically.

Thanks for any help,
Fred



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Adding a reference programatically

Sub AddADO()

Dim R

For Each R In ThisWorkbook.VBProject.References
If R.GUID = "{00000205-0000-0010-8000-00AA006D2EA4}" And R.Major = 2
Then
Exit Sub
End If
Next

On Error GoTo NOTFOUND

'although usually the ADO version will be higher, doing Minor:=0 will
install
'the higher version if available. On the other hand when you specify
Minor:=5
'and only a lower version is available, this can't be installed
'----------------------------------------------------------------------------
ThisWorkbook.VBProject.References.AddFromGuid _
GUID:="{00000205-0000-0010-8000-00AA006D2EA4}", _
Major:=2, Minor:=0
Exit Sub

NOTFOUND:
On Error GoTo 0

End Sub


RBS


"Fred" <leavemealone@home wrote in message
...
I create a new workbook simply by copying a worksheet, i.e.
ActiveSheet.copy.
The problen is that the sheet has subroutines that require the ADODB and
so the new workbook needs to reference the Microsoft ActiveX Data Objects
Library.
I know I can add that reference to the new workbook using Tools:References
from the main menu but how can I add that reference to the new workbook
programmatically.

Thanks for any help,
Fred




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Adding a reference programatically

Seems to me you would only set a version if your code required that or a
newer to work, then test for a failure.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Sub AddADO()

Dim R

For Each R In ThisWorkbook.VBProject.References
If R.GUID = "{00000205-0000-0010-8000-00AA006D2EA4}" And R.Major = 2
Then
Exit Sub
End If
Next

On Error GoTo NOTFOUND

'although usually the ADO version will be higher, doing Minor:=0 will
install
'the higher version if available. On the other hand when you specify
Minor:=5
'and only a lower version is available, this can't be installed
'----------------------------------------------------------------------------
ThisWorkbook.VBProject.References.AddFromGuid _
GUID:="{00000205-0000-0010-8000-00AA006D2EA4}", _
Major:=2, Minor:=0
Exit Sub

NOTFOUND:
On Error GoTo 0

End Sub


RBS


"Fred" <leavemealone@home wrote in message
...
I create a new workbook simply by copying a worksheet, i.e.
ActiveSheet.copy.
The problen is that the sheet has subroutines that require the ADODB and
so the new workbook needs to reference the Microsoft ActiveX Data Objects
Library.
I know I can add that reference to the new workbook using Tools:References
from the main menu but how can I add that reference to the new workbook
programmatically.

Thanks for any help,
Fred





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Adding a reference programatically

Not sure what you are precisely saying.
Would you alter the posted code?

RBS

"Tom Ogilvy" wrote in message
...
Seems to me you would only set a version if your code required that or a
newer to work, then test for a failure.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Sub AddADO()

Dim R

For Each R In ThisWorkbook.VBProject.References
If R.GUID = "{00000205-0000-0010-8000-00AA006D2EA4}" And R.Major
= 2
Then
Exit Sub
End If
Next

On Error GoTo NOTFOUND

'although usually the ADO version will be higher, doing Minor:=0 will
install
'the higher version if available. On the other hand when you specify
Minor:=5
'and only a lower version is available, this can't be installed

'----------------------------------------------------------------------------
ThisWorkbook.VBProject.References.AddFromGuid _
GUID:="{00000205-0000-0010-8000-00AA006D2EA4}", _
Major:=2, Minor:=0
Exit Sub

NOTFOUND:
On Error GoTo 0

End Sub


RBS


"Fred" <leavemealone@home wrote in message
...
I create a new workbook simply by copying a worksheet, i.e.
ActiveSheet.copy.
The problen is that the sheet has subroutines that require the ADODB
and
so the new workbook needs to reference the Microsoft ActiveX Data
Objects
Library.
I know I can add that reference to the new workbook using
Tools:References
from the main menu but how can I add that reference to the new workbook
programmatically.

Thanks for any help,
Fred






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding a reference programatically

I was saying why not set both major and minor to zero unless your code
requires a certain version (or newer).

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote in message
...
Not sure what you are precisely saying.
Would you alter the posted code?

RBS

"Tom Ogilvy" wrote in message
...
Seems to me you would only set a version if your code required that or a
newer to work, then test for a failure.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Sub AddADO()

Dim R

For Each R In ThisWorkbook.VBProject.References
If R.GUID = "{00000205-0000-0010-8000-00AA006D2EA4}" And

R.Major
= 2
Then
Exit Sub
End If
Next

On Error GoTo NOTFOUND

'although usually the ADO version will be higher, doing Minor:=0

will
install
'the higher version if available. On the other hand when you

specify
Minor:=5
'and only a lower version is available, this can't be installed


'---------------------------------------------------------------------------
-
ThisWorkbook.VBProject.References.AddFromGuid _
GUID:="{00000205-0000-0010-8000-00AA006D2EA4}", _
Major:=2, Minor:=0
Exit Sub

NOTFOUND:
On Error GoTo 0

End Sub


RBS


"Fred" <leavemealone@home wrote in message
...
I create a new workbook simply by copying a worksheet, i.e.
ActiveSheet.copy.
The problen is that the sheet has subroutines that require the ADODB
and
so the new workbook needs to reference the Microsoft ActiveX Data
Objects
Library.
I know I can add that reference to the new workbook using
Tools:References
from the main menu but how can I add that reference to the new

workbook
programmatically.

Thanks for any help,
Fred










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Adding a reference programatically

Yes, could do that, but found that Major:=2 is always there.

RBS

"Tom Ogilvy" wrote in message
...
I was saying why not set both major and minor to zero unless your code
requires a certain version (or newer).

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote in message
...
Not sure what you are precisely saying.
Would you alter the posted code?

RBS

"Tom Ogilvy" wrote in message
...
Seems to me you would only set a version if your code required that or
a
newer to work, then test for a failure.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote:

Sub AddADO()

Dim R

For Each R In ThisWorkbook.VBProject.References
If R.GUID = "{00000205-0000-0010-8000-00AA006D2EA4}" And

R.Major
= 2
Then
Exit Sub
End If
Next

On Error GoTo NOTFOUND

'although usually the ADO version will be higher, doing Minor:=0

will
install
'the higher version if available. On the other hand when you

specify
Minor:=5
'and only a lower version is available, this can't be installed


'---------------------------------------------------------------------------
-
ThisWorkbook.VBProject.References.AddFromGuid _
GUID:="{00000205-0000-0010-8000-00AA006D2EA4}", _
Major:=2, Minor:=0
Exit Sub

NOTFOUND:
On Error GoTo 0

End Sub


RBS


"Fred" <leavemealone@home wrote in message
...
I create a new workbook simply by copying a worksheet, i.e.
ActiveSheet.copy.
The problen is that the sheet has subroutines that require the ADODB
and
so the new workbook needs to reference the Microsoft ActiveX Data
Objects
Library.
I know I can add that reference to the new workbook using
Tools:References
from the main menu but how can I add that reference to the new

workbook
programmatically.

Thanks for any help,
Fred









Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding VB code to worksheet programatically seegerp Excel Programming 2 March 29th 06 09:52 PM
Adding a Control programatically Richard Buttrey Excel Programming 9 July 5th 05 08:34 AM
default references or adding programatically sebastienm Excel Programming 0 August 25th 04 09:31 PM
Programatically adding worksheets to a spreadsheet Scott Lyon Excel Programming 4 August 8th 03 02:54 PM
Adding components to multipage programatically Nigel Brown[_2_] Excel Programming 0 August 4th 03 10:25 AM


All times are GMT +1. The time now is 12:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"