Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default Checking/Setting a reference on open

Is there a way to have VBA check to see if there is a reference and, if not, set it on an
open event?

I need to set a reference to the "Microsoft Shell Controls and Automation" object if it's
not already set.
(it will save me having to guide someone over the phone-albeit not a long trip!)

xl2kPro
--
Regards;
Rob
------------------------------------------------------------------------


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default Checking/Setting a reference on open

Hi Rob

this code will set the reference for the activeworkbook.

Sub addReference()

Const REF_FULL_NAME As String = "C:\Windows\System32\Shell32.dll"
Const REF_SHORT_NAME As String = "Shell32"

Dim objRef As Object

On Error Resume Next '//ignore the error if it doesn't exist
Set objRef = ActiveWorkbook.VBProject.References.Item(REF_SHORT _NAME)
On Error GoTo 0

If objRef Is Nothing Then
ActiveWorkbook.VBProject.References.AddFromFile (REF_FULL_NAME)
Else
'already set so do nothing
End If

End Sub

HTH

Barry

"RWN" wrote:

Is there a way to have VBA check to see if there is a reference and, if not, set it on an
open event?

I need to set a reference to the "Microsoft Shell Controls and Automation" object if it's
not already set.
(it will save me having to guide someone over the phone-albeit not a long trip!)

xl2kPro
--
Regards;
Rob
------------------------------------------------------------------------



  #3   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default Checking/Setting a reference on open

Barry;

Looks wonderful, I'll try it tomorrow.

Thanks.

--
Regards;
Rob
------------------------------------------------------------------------
"Barry" wrote in message
...
Hi Rob

this code will set the reference for the activeworkbook.

Sub addReference()

Const REF_FULL_NAME As String = "C:\Windows\System32\Shell32.dll"
Const REF_SHORT_NAME As String = "Shell32"

Dim objRef As Object

On Error Resume Next '//ignore the error if it doesn't exist
Set objRef = ActiveWorkbook.VBProject.References.Item(REF_SHORT _NAME)
On Error GoTo 0

If objRef Is Nothing Then
ActiveWorkbook.VBProject.References.AddFromFile (REF_FULL_NAME)
Else
'already set so do nothing
End If

End Sub

HTH

Barry

"RWN" wrote:

Is there a way to have VBA check to see if there is a reference and, if not, set it on

an
open event?

I need to set a reference to the "Microsoft Shell Controls and Automation" object if

it's
not already set.
(it will save me having to guide someone over the phone-albeit not a long trip!)

xl2kPro
--
Regards;
Rob
------------------------------------------------------------------------





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
Checking formula type (reference to other worksheet or not) topola Excel Discussion (Misc queries) 2 July 23rd 07 10:48 AM
Checking to see if a sheet is open Frank Kabel Excel Programming 1 September 10th 04 04:15 AM
Checking for Open Files Marston Excel Programming 2 August 16th 04 04:01 PM
Disabling Circular Reference Checking Adrian[_7_] Excel Programming 1 July 31st 04 09:15 AM
Checking for Open Workbook sbharbour Excel Programming 6 August 28th 03 11:42 PM


All times are GMT +1. The time now is 07:37 AM.

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

About Us

"It's about Microsoft Excel"