T
Thomas Gahler
Hi folks
I have a problem with my addin and the reference set to this file.
I develop an addin (Library.dot) that is stored in words startup-path
(subdirectory of winword.exe). In Tools / Options this path is also set in
the AutoStart-entry.
After that, I create a new template set an referenc to my Library.dot and
use this second file as an addin too. This addin will automaticlly loaded in
the AutoExec of the Library.dot (this all is made on WinXp & OfficeXP).
Now I change to my other PC (Win2000 & Office2003 SP2) and copy my two
files. One somewhere on the pc and the Library.dot to words startup-path.
Both directory are different (different drive and path) to the first
computer. Everything works fine an word automaticlly update the reference to
the new envrionment.
After this check, I sent the two files to the customer. He installed the
files the same way (one somewhere in the pc ad the other one to words
starup-path. He has the same configuration on his machine (Win2000 &
Office2003 SP2) but different file locations. In Tolls / Options the
AutoStart-entry is also set to words startup-folder.
When he starts word, I get a MsgBox (see code below), because the reference
was updated.
Public Function funcCheckReference( _
ByVal CAddinProjektName As String, _
ByVal CAddinName As String, _
ByVal CLibraryProjektName As String, _
ByVal CLibraryAddinName As String) As Boolean
Dim bReferenceExist As Boolean
Dim iReference As Integer
Dim iCounter As Integer
Dim oAddIn As Word.Template
bReferenceExist = True
'If Reference is broken, restore it
'(Code based of Dave Rado's code example)
On Error Resume Next
With Application.VBE.VBProjects(CAddinProjektName).References
For iCounter = 1 To .Count
'If there is no reference set, resumes next.
'If there is a reference set but it is broken, removes it.
If .Item(iCounter).IsBroken Then
.Remove .Item(iCounter)
'Sets the reference - if already set, resumes next
iReference = .Count
.AddFromFile Options.DefaultFilePath(wdStartupPath) & "\" &
CLibraryAddinName
'Check if a reference is added and save the right addin.
If Not (iReference = .Count) Then
For Each oAddIn In Templates
If Not InStr(0, oAddIn.Name, CAddinName, vbTextCompare) =
0 Then
bReferenceExist = False
'...some code removed here...
MsgBox "Reference updated"
Exit For
End If
Next oAddIn
End If
End If
Next iCounter
End With
On Error GoTo 0
funcCheckReference = bReferenceExist
End Function
I allways thougt, that word will automaticlly update a broken reference, if
the addin is stored in words startup-folder.
Why does it work on my computer and does it not work on my customers
computer? Does anybody has an idee?
Thanks for help
BTW: same posting is set in 'microsoft.public.word.word97vba'
--
Thomas Gahler
MVP für WordVBA
Co-Autor von »Microsoft Word-Programmierung.
Das Handbuch« (MS Press)
- Windows XP (SP2), Office XP (SP3)
I have a problem with my addin and the reference set to this file.
I develop an addin (Library.dot) that is stored in words startup-path
(subdirectory of winword.exe). In Tools / Options this path is also set in
the AutoStart-entry.
After that, I create a new template set an referenc to my Library.dot and
use this second file as an addin too. This addin will automaticlly loaded in
the AutoExec of the Library.dot (this all is made on WinXp & OfficeXP).
Now I change to my other PC (Win2000 & Office2003 SP2) and copy my two
files. One somewhere on the pc and the Library.dot to words startup-path.
Both directory are different (different drive and path) to the first
computer. Everything works fine an word automaticlly update the reference to
the new envrionment.
After this check, I sent the two files to the customer. He installed the
files the same way (one somewhere in the pc ad the other one to words
starup-path. He has the same configuration on his machine (Win2000 &
Office2003 SP2) but different file locations. In Tolls / Options the
AutoStart-entry is also set to words startup-folder.
When he starts word, I get a MsgBox (see code below), because the reference
was updated.
Public Function funcCheckReference( _
ByVal CAddinProjektName As String, _
ByVal CAddinName As String, _
ByVal CLibraryProjektName As String, _
ByVal CLibraryAddinName As String) As Boolean
Dim bReferenceExist As Boolean
Dim iReference As Integer
Dim iCounter As Integer
Dim oAddIn As Word.Template
bReferenceExist = True
'If Reference is broken, restore it
'(Code based of Dave Rado's code example)
On Error Resume Next
With Application.VBE.VBProjects(CAddinProjektName).References
For iCounter = 1 To .Count
'If there is no reference set, resumes next.
'If there is a reference set but it is broken, removes it.
If .Item(iCounter).IsBroken Then
.Remove .Item(iCounter)
'Sets the reference - if already set, resumes next
iReference = .Count
.AddFromFile Options.DefaultFilePath(wdStartupPath) & "\" &
CLibraryAddinName
'Check if a reference is added and save the right addin.
If Not (iReference = .Count) Then
For Each oAddIn In Templates
If Not InStr(0, oAddIn.Name, CAddinName, vbTextCompare) =
0 Then
bReferenceExist = False
'...some code removed here...
MsgBox "Reference updated"
Exit For
End If
Next oAddIn
End If
End If
Next iCounter
End With
On Error GoTo 0
funcCheckReference = bReferenceExist
End Function
I allways thougt, that word will automaticlly update a broken reference, if
the addin is stored in words startup-folder.
Why does it work on my computer and does it not work on my customers
computer? Does anybody has an idee?
Thanks for help
BTW: same posting is set in 'microsoft.public.word.word97vba'
--
Thomas Gahler
MVP für WordVBA
Co-Autor von »Microsoft Word-Programmierung.
Das Handbuch« (MS Press)
- Windows XP (SP2), Office XP (SP3)