rgmatthes
09-19-2011, 01:47 PM
(Mods, please delete http://www.vbaexpress.com/forum/showthread.php?t=39072 (http://www.vbaexpress.com/forum/showthread.php?t=39072). This topic clarifies my problem.)
I have a few hundred Word templates (DOTX) on a SharePoint site. Many teams of users work with these templates.
When a user needs to customize this documentation, they click a special link on SharePoint to generate a new document (DOCX) from the template they choose. This new document file always needs to be "linked" back to its template file on SharePoint. If the document loses that link, it won’t work correctly and is considered “broken”.
When documents break, I need to re-establish the link back to the right template on SharePoint. It makes sense to do this programmatically so I can distribute the solution to my team.
I want to give each template file a unique Template ID (a three-digit number), stored in metadata or a custom file property. When new documents are generated from the templates, the Template ID automatically carries over into the document, so that’s set. Now I just need to use VBA to scan the template files in the SharePoint document library for the matching Template ID. When that’s found, I can re-establish the link and all is well.
I’m basically looking for this:
Sub DocFixer()
Dim objTemplate as Template
Dim objBrokenDoc as Document
Set objBrokenDoc = ActiveDocument
For each objTemplate in "\\SharePoint\Template Library\".Templates
If objTemplate.Properties("Template ID").Value = objBrokenDoc.Properties("Template ID").Value Then
objBrokenDoc.AttachedTemplate = objTemplate.Path
Exit For
End If
Next
End Sub
…but I’m having trouble using VBA to read SharePoint doc library contents without actually opening the contents, as that takes far too long with so many templates, plus its very disruptive for the user.
Any ideas? Could you point me in the right direction?
I have a few hundred Word templates (DOTX) on a SharePoint site. Many teams of users work with these templates.
When a user needs to customize this documentation, they click a special link on SharePoint to generate a new document (DOCX) from the template they choose. This new document file always needs to be "linked" back to its template file on SharePoint. If the document loses that link, it won’t work correctly and is considered “broken”.
When documents break, I need to re-establish the link back to the right template on SharePoint. It makes sense to do this programmatically so I can distribute the solution to my team.
I want to give each template file a unique Template ID (a three-digit number), stored in metadata or a custom file property. When new documents are generated from the templates, the Template ID automatically carries over into the document, so that’s set. Now I just need to use VBA to scan the template files in the SharePoint document library for the matching Template ID. When that’s found, I can re-establish the link and all is well.
I’m basically looking for this:
Sub DocFixer()
Dim objTemplate as Template
Dim objBrokenDoc as Document
Set objBrokenDoc = ActiveDocument
For each objTemplate in "\\SharePoint\Template Library\".Templates
If objTemplate.Properties("Template ID").Value = objBrokenDoc.Properties("Template ID").Value Then
objBrokenDoc.AttachedTemplate = objTemplate.Path
Exit For
End If
Next
End Sub
…but I’m having trouble using VBA to read SharePoint doc library contents without actually opening the contents, as that takes far too long with so many templates, plus its very disruptive for the user.
Any ideas? Could you point me in the right direction?