Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

getting attached template if link broken

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lauro - 07 Aug 2005 19:24 GMT
I want to populate an array  with the name of the file based on a
template "MyTemplate.dot" also if the reference of the full path of
MyTemplate.dot is not valid anymore (for instance if the template is
not on the computer of the user or if it is in a different folder).

' -- I have a global variable
Public gArrFilesOpen() as string

'--using the following routine everything is OK only if Word is
'--finding "MyTemlate.dot" in the right place, otherwise
'--AttachedTemplate reports "normal.dot"

Function PopulateArray() as Long
'report -1 if an error occurs, otherwise the number of files found
dim objWordApp as Word.Application
dim objWordDoc as Word.Document
dim lngNumFileOpen as Long

 On Error Goto Err_PopulateArray
  lngNumFileOpen = 0   
  Set objWordApp = GetObject(, "Word.Application")
  For Each objWordDoc In objWordApp.Documents
     If objWordDoc.AttachedTemplate.Name = "MyTemplate.dot" Then
        lngNumFileOpen = lngNumFileOpen + 1
        ReDim Preserve gArrFilesOpen(lngNumFileOpen)
        gArrFilesOpen(lngNumFileOpen) = objWordDoc.Name
     End If
  Next
  PopulateArray= lngNumFileOpen
   
Exit_PopulateArray:
  set objWordApp = nothing
  set objWordDoc = nothing
  exit Function
Err_PopulateArray:
 lngNumFileOpen=-1
 Resume Exit_PopulateArray
end Function

'--To include also the file with broken reference I tried to use the
'--right iformation provided by the window "Add-in and Templates"
' --so I used a simple function to get rid of the path and get only
'--the name of the template and then I used
'-- Dialogs(wdDialogToolsTemplates).Template instead of
'--Attachedtempalte as follows:

Function GetNameFromFullName(strFullName As String) As String
'just to get rid of the path
Dim i As Integer
  i = InStrRev(strFullName, "\")
  If i > 0 Then
   GetNameFromFullName = Mid(strFullName, i + 1)
  Else
     GetNameFromFullName = ""
  End If  
End Function

Function PopulateArray() as Long
'report -1 if an error occurs, otherwise the number of files found
dim objWordApp as Word.Application
dim objWordDoc as Word.Document
dim lngNumFileOpen as Long

 On Error Goto Err_PopulateArray
  lngNumFileOpen = 0   
  Set objWordApp = GetObject(, "Word.Application")
  For Each objWordDoc In objWordApp.Documents
     If GetNameFromFullName( _  objWordDoc.Application.Dialogs( _
       wdDialogToolsTemplates).Template) = "MyTemplate.dot" Then
          lngNumFileOpen = lngNumFileOpen + 1
         ReDim Preserve gArrFilesOpen(lngNumFileOpen)
         gArrFilesOpen(lngNumFileOpen) = objWordDoc.Name
     End If
  Next
  PopulateArray= lngNumFileOpen
   
Exit_PopulateArray:
  set objWordApp = nothing
  set objWordDoc = nothing
  exit Function
Err_PopulateArray:
 lngNumFileOpen=-1
 Resume Exit_PopulateArray
end Function

'-- But the latter doesn't work because it all depend from the first
Word document found. It is like the information doesn't change for
every file.

Any suggestions?

Thanks, Lauro
Cindy Meister - 08 Aug 2005 07:48 GMT
Replied to this duplicate question in one of the office.developer newsgroups

 -- Cindy

> I want to populate an array  with the name of the file based on a
> template "MyTemplate.dot" also if the reference of the full path of
[quoted text clipped - 88 lines]
>
> Thanks, Lauro
Lauro - 08 Aug 2005 12:57 GMT
Sorry for the cross-posting.

lauro

>Replied to this duplicate question in one of the office.developer newsgroups
>
[quoted text clipped - 92 lines]
>>
>> Thanks, Lauro
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.