PDA

View Full Version : [SOLVED:] Checked references not available to code



Daedal1
09-16-2015, 11:55 AM
Working in Word 2010; have a procedure that uses FileSystemObject so I need to reference Scripting Runtime (scrrun.dll). Want to use VBA to make sure scripting is available so I can distribute the procedure.

My References list looks like this:

14404

Code to list available References looks like this:

Sub ListRefs()
Dim ref As Reference
Dim sRefs As String


With ActiveDocument.VBProject
sRefs = "There are " & .References.Count & " references listed:" & vbCrLf
For Each ref In .References
sRefs = sRefs & " " & ref.Name & vbCrLf
Next ref
End With
MsgBox sRefs
End Sub


MsgBox displays this:

14405

Questions:
1) How come only 5 of the 9 references are available thru the object model?
2) I'm open to recommendations on the optimal way to accomplish what I hope to accomplish if I'm going about this the hard way (my tendency).

Thanks in advance for any light you can shed on this.

Scot

gmayor
09-16-2015, 09:49 PM
The message box shows only 5 references is that the document project itself has only five checked. Your illustration shows the Normal template's references. To see the difference run the following


Sub ListRefs()
Dim ref As Object
Dim sRefs As String
With ThisDocument.VBProject
sRefs = "There are " & .References.Count & " references listed:" & vbCrLf
For Each ref In .References
sRefs = sRefs & " " & ref.name & vbCrLf
Next ref
End With
MsgBox sRefs
End Sub

Commands from installed, but unchecked, object libraries can be adopted, provided you use Late Binding to the reference. e.g.


Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")

Daedal1
09-17-2015, 07:04 AM
Graham -- Thanks so much for the quick response. Had to drill down from other threads the "ThisDocument" concept and now see the reason for the results I was producing. The late binding/early binding concept is one I've never fully grokked, but I have been taught in my formative years that late binding generally is a bad thing so I never really learned to appreciate its beneficial implementation.

Marking as Resolved and off to break more stuff. Thanks Again!