PDA

View Full Version : Solved: Application.OrganizerCopy



fionabolt
10-21-2009, 07:51 AM
I have been asked to update some templates to update (over 2000 of them!).

My issue is that all the templates require new code, but the existing code has been stored in ThisDocument rather than in modules.

Application.OrganizerCopy is only useful for transfering projects stored as modules.

Can anyone help, or point me in the right direction, for Automating extracting the code from ThisDocument from one template, and populating the new template with the same code (either still in ThisDocument, or in a new module).

Many thanks

fionabolt
10-21-2009, 08:08 AM
Sorry - I've just solved my own problem. Just needed to "Trust Access to Visual Basic Project" first.

Function CopyCodeModule(SourceFile As String, DestinationFile As String)
Dim proj
Set proj = ActiveDocument.AttachedTemplate.VBProject.VBComponents
For p = 1 To proj.Count
Debug.Print proj(p).Name
Application.OrganizerCopy _
Source:=SourceFile, _
Destination:=DestinationFile, _
Name:=proj(p).Name, _
Object:=wdOrganizerObjectProjectItems
End If
Next
End Function