Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Checking formula type (reference to other worksheet or not) | Excel Discussion (Misc queries) | |||
Checking to see if a sheet is open | Excel Programming | |||
Checking for Open Files | Excel Programming | |||
Disabling Circular Reference Checking | Excel Programming | |||
Checking for Open Workbook | Excel Programming |