A
axeman
Ok, so I'm building this form that will cycle through a range of documents.
The range may vary depending on user selection. That is, the module that
processes the information may cycle through as little as 5 documents (sets
values from the text fields into the fields on the documents) to as many as
maybe 20 documents. What is the fastest way to get this done? Some documents
do not have any fields in them so they don't require any information to be
added to them but they do need to be copied over to another folder for the
user to browse. I have attached the code that I have used for this below. My
problem I believe that this code can run faster I just don't know how. Is
there any way to tell if a document has bookmarks without opening it? That
would definitely cut down on the processing time I think. Any suggestions are
welcome!!!!
Code: (startList & endList are defined in a separate module: current range
is 5-16)
For i = startList To endList
' Opens, saves, and closes each document
Set oDoc = Documents.Open(templateDir + Template$(i) + ".dot",
Visible:=False)
oDoc.ActiveWindow.SetFocus
oDoc.ActiveWindow.View.Type = wdPrintView
If oDoc.Bookmarks.Count >= 1 Then
Application.Run MacroName:="SetFormFieldInfo"
oDocSaveName = Template$(i) + ".doc"
oDoc.SaveAs FileName:=saveDir + oDocSaveName,
AddToRecentFiles:=False
Else:
WordBasic.CopyFileA templateDir + rifTemplate$(i) + ".dot",
saveDir + Template$(i) + ".doc"
End If
oDoc.Close
Next i
The range may vary depending on user selection. That is, the module that
processes the information may cycle through as little as 5 documents (sets
values from the text fields into the fields on the documents) to as many as
maybe 20 documents. What is the fastest way to get this done? Some documents
do not have any fields in them so they don't require any information to be
added to them but they do need to be copied over to another folder for the
user to browse. I have attached the code that I have used for this below. My
problem I believe that this code can run faster I just don't know how. Is
there any way to tell if a document has bookmarks without opening it? That
would definitely cut down on the processing time I think. Any suggestions are
welcome!!!!
Code: (startList & endList are defined in a separate module: current range
is 5-16)
For i = startList To endList
' Opens, saves, and closes each document
Set oDoc = Documents.Open(templateDir + Template$(i) + ".dot",
Visible:=False)
oDoc.ActiveWindow.SetFocus
oDoc.ActiveWindow.View.Type = wdPrintView
If oDoc.Bookmarks.Count >= 1 Then
Application.Run MacroName:="SetFormFieldInfo"
oDocSaveName = Template$(i) + ".doc"
oDoc.SaveAs FileName:=saveDir + oDocSaveName,
AddToRecentFiles:=False
Else:
WordBasic.CopyFileA templateDir + rifTemplate$(i) + ".dot",
saveDir + Template$(i) + ".doc"
End If
oDoc.Close
Next i