Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Problem with Word object libraries

  Asked By: Glenn    Date: Nov 29    Category: MS Office    Views: 640
  

I have enabled the Word 10.0 object library in my Excel VBA code to
allow code that protects word files as part of my application. This
version of the object library is associated with Office 2002. If a
user with Office 2003 opens the file, Excel automatically replaces the
Word 10.0 object library reference with version 11.0. After this file
is saved and subsequently opened by a user with Excel 2002 they will
get a compile error message because Excel 2002 doesn't recognize the
11.0 object reference which now exists in the file. I need a way to
lock down the older version of the object library. Any suggestions on
how this can be done, or an alternative workaround would be appreciated.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Grace Ellis     Answered On: Nov 29

Below is code  to dump references to the immediate window. I realise that
this doesn't solve your problem  but maybe it's a wavering pointer :)

I also include a function to check for specific references in one of my
applications.
I recognize it prob won't fit for you but maybe you can tweak it.

The definitive routines as far as I'm concerned are from

There are references to subs that you obviously won't have the major one
being subShowMsg.
Apologies but I've just lifted this from my own code to try and give an
idea.

I make no apololies for untidy code. I'm working on a routine for that :)

If you need more or want the rest of the code just holla!!


Sub subDumpRefs()
' Dump a list of references to the immediate window.

Dim olRef As Object
Dim ilRefCount As Integer
Dim ilRef As Integer
Dim slName As String
Dim slFullPath As String
Dim slBuiltIn As String
Dim slGUID As String
Dim slIsBroken As String
Dim slVersion As String
Dim dlKind As String
Dim slDescription As String

ilRefCount = Application.VBE.ActiveVBProject.References.count
ilRef = 0
For Each olRef In Application.VBE.ActiveVBProject.References

ilRef = ilRef + 1
slDescription = olRef.Description
slName = olRef.Name
slGUID = olRef.GUID
slVersion = olRef.Major & "." & olRef.Minor
If olRef.isbroken Then
slIsBroken = "TRUE"
slFullPath = ""
Else
slIsBroken = "FALSE"
slFullPath = olRef.FullPath
End If
If olRef.BuiltIn Then
slBuiltIn = "TRUE"
Else
slBuiltIn = "FALSE"
End If

Debug.Print "Reference " & ilRef & "/" & ilRefCount _
& vbCrLf & " Name:" & slName _
& vbCrLf & "Description:" & slDescription _
& vbCrLf & " Full Path:" & slFullPath _
& vbCrLf & " Version:" & slVersion _
& vbCrLf & " GUID:" & slGUID _
& vbCrLf & " Built In:" & slBuiltIn _
& vbCrLf & " Broken:" & slIsBroken _
& vbCrLf

Next olRef

End Sub
----------------------------------------------------------------------------
--------------------------
' If references are missing we have to stop.
slRefError = fncCheckReferences()
If slRefError <> "" Then
subShowMsg sgMsg(133) & slRefError, cgMSgBox
bgOptAbort = True
Exit Sub
End If
----------------------------------------------------------------------------
---------------------------
Function fncCheckReferences() _
As String
sgProcName = "fncCheckReferences"
' Return "" if all references are OK.
' Return the bad reference name if not.

' These items MUST be referenced.
' 1 The VBIDE.... Name = VBIDE
' In order to reference the references.
' 2 The template.... Name = TemplateProject
' For the styles/autotexts.
' 3 Scripting runtime.... Name = Scripting
' For File/Folder actions.. exists/create etc.

' Note that this is all hard coded.
' Only the NAMES are checked at the moment until
' we know if more is nessesary.
' Properties to check could be Name, GUID, Description.
' One of these sometimes has MISSING in
' it which is also a problem.

Dim olRText As AutoTextEntry
Dim olRef As Reference
Dim olReferences As References
Dim ilRefCount As Integer
Dim ilRef As Integer
Dim slName As String
Dim slFullPath As String
Dim slBuiltIn As String
Dim slGUID As String
Dim slIsBroken As String
Dim slVersion As String
Dim dlKind As String
Dim slDescription As String
Dim slScripting As String
Dim slTemplate As String
Dim slVBIDE As String
Dim slMsg As String
Dim blScripting As Boolean
Dim blTemplate As Boolean
Dim ilN As Integer
Dim olProj As VBProject

subShowMsg sgMsg(140) & sgRefDorthe
For ilN = 1 To Application.VBE.VBProjects.count
Set olProj = Application.VBE.VBProjects(ilN)
If UCase(olProj.Name) = sgRefDorthe Then
Exit For
End If
Next ilN
If IsNull(olProj) Then
slMsg = sgMsg(142)
fncCheckReferences = slMsg
Exit Function
End If

subShowMsg sgMsg(140)
On Error Resume Next
Set olReferences = olProj.References
If Err.Number <> 0 Then
On Error GoTo 0
fncCheckReferences = "VBIDE"
Exit Function
End If
On Error GoTo 0

ilRef = 0
blScripting = False
blTemplate = False
ilRefCount = olReferences.count

subShowMsg sgMsg(135) _
& sgRefScripting _
& " & " _
& sgRefTemplate
slScripting = UCase(sgRefScripting)
slTemplate = UCase(sgRefTemplate)
For Each olRef In olReferences

ilRef = ilRef + 1
slDescription = olRef.Description
slName = UCase(olRef.Name)
slGUID = olRef.GUID
slVersion = olRef.Major & "." & olRef.Minor

Select Case slName
Case slScripting
blScripting = True
Case slTemplate
blTemplate = True
Case Else
End Select

If olRef.isbroken Then
slMsg = slName & " " & sgMsg(89)
fncCheckReferences = slMsg
Exit Function
End If

Next olRef

slMsg = ""
If Not blScripting Then
slMsg = sgRefScripting
End If
If Not blTemplate Then
If slMsg = "" Then
slMsg = sgRefTemplate
Else
slMsg = slMsg & "/" & sgRefTemplate
End If
End If
fncCheckReferences = slMsg


End Function

 
Answer #2    Answered By: Alisha Johnson     Answered On: Nov 29

I fogot the link....

It's to http://reliableanswers.com/VB/Samples.asp#mRA
and http://reliableanswers.com/dl?mRA_Startup.zip

This is from Shawn who is a regular contributer to these forums and is *the*
doyen of startup and references...

 
Answer #3    Answered By: Varick Fischer     Answered On: Nov 29

You will want to change how you code  your application  so that you can use
Late Binding. Late Binding will get the appropriate object  library which is
determined by the user.

Late Bound:
Dim objWord as Object
Set objWord=CreateObject("Word.Application")
objWord.Visible=True
objWord.Documents.Add
objWord.Quit
Set objWord=Nothing

Early Bound:
Dim objWord As New Word.Application
objWord.Visible = True
objWord.Documents.Add
objWord.Quit

There have been a couple of times where I needed to use Late Binding. These
instances have been when I did not know which version of Outlook I would be
attaching to. I would set my variable to Early Binding, so I would have the
intellisense that I needed while programming, and then when I was ready to
distribute the code, I'd change the variable so that it would be looking for
Late Binding. Here is my code sample, perhaps it will help:

#If EarlyBinding = 1 Then
Public objOLapp As Outlook.Application
Public objOLitem As Outlook.MailItem
#Else
Public objOLapp As Object
Public objOLitem As Object
#End If

Sub CombineEmailAddresses()
Dim strCell As String
Dim strEmail As String
Dim strActiveSheetName As String
On Error GoTo EH
'Sort the blank email addresses to the end of the list
Selection.Sort Key1:=Range("M2"), Order1:=xlAscending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

'Position the cursor at the first email address
Application.GoTo Reference:="R2C13"

'Loop through all the addresses and combine them
Do While ActiveCell.Value <> ""
strCell = ActiveCell.Value
strEmail = strEmail & strCell & "; "
ActiveCell.Offset(1, 0).Range("A1").Select
Loop

Debug.Print strEmail

'Return the sort to how it was before
Selection.Sort Key1:=Range("a2"), Order1:=xlAscending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Test (strEmail)
'Handle Errors Gracefully
Exit_EH:
Exit Sub

EH:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_EH

End Sub

Sub Test(strEmail As String)
On Error GoTo EH
Dim objOLapp As Object
Dim objOLitem As Object
Set objOLapp = CreateObject("Outlook.Application")
Set objOLitem = objOLapp.CreateItem(0)
With objOLitem
.Subject = ""
.CC = ""
.To = ""
.Body = ""
.bcc = strEmail
' .Attachments.Add '(path to the attachment,either hard coded or
variable)
.Display
End With
Set objOLapp = Nothing
Set objOLitem = Nothing
'Handle Errors Gracefully
Exit_EH:
Exit Sub

EH:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_EH

End Sub

 
Didn't find what you were looking for? Find more on Problem with Word object libraries Or get search suggestion and latest updates.




Tagged: