Am Thu, 26 Oct 2006 23:43:02 UTC, schrieb Compass Rose
2) Why is ScreenUpdating turned off during the process?
Otherwise you would see a constant flicker of all 50 newly created
documents on the screen as they are created and saved.
Thanks to Greg Maxey for making me aware of that ... I was looking
for that for a current project without knowing about it...
If using it, one might consider to change System.Cursor =
wdCursorWait, and storing the previous cursor form in a variable and
restoring this at the end of the procedure:
Dim previousCursor As Long
previousCursor = System.Cursor
System.Cursor = wdCursorWait
Application.ScreenUpdating = False
' do something taking long time
Application.ScreenUpdating = True
System.Cursor = previousCursor
3) How could the code be modified to read all of the documents in a
particular folder, perform the operation on all the files in that folder (one
at a time, of course)and then save them to the newly created folder using the
same file name?
using the FSO, er, the FileSystemObject
Dim fso, sourceFolder, destinationFolder, myTemplate, templateFiles
_
As Object
Dim newDocument As Document
Dim newPath As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set sourceFolder = fso.GetFolder(some_String_with_the_Path)
If NOT fso.FolderExists(some_String_with_destination_Path)
Set destinationFolder = _
fso.CreateFolder(some_String_with_destination_Path)
Else
Set destinationFolder = _
fso.GetFolder(some_String_with_destination_Path)
End If
newPath = destinationFolder.Path
Set templateFiles = sourceFolder.Files
For Each myTemplate IN templateFiles
IF UCase(fso.GetExtensionName(myTemplate.Path)) = "DOT" _
OR myTemplate.Type = "Word Template" Then
Application.Documents.Add _
Template := myTemplate.Path & myTemplate.Name
' not sure, if the Path property does not already
' contain the full name
newDocument = ActiveDocument
newDocument.BuiltInDocumentProperties(wdPropertyTitle) _
= newProjectName _
& " " & newDocument.BuiltInProperties(wdPropertyTitle)
' add more BuiltInDocumentProperties, CustomDocumentProperties,
' or Variables as needed
newDocument.SaveAs FileName := newPath _
& fso.GetBaseName(myTemplate.Name) & ".doc" _
, FileFormat := wdFormatDocument _
, AddToRecentFiles := False ' maybe...
NewDocument.Close
End If
Next aFile
' -----------------------
Just typed, not compiled or tested.
Check out the meaning of "Path" and "Name" in the FSO (btw, I think
that there is some "FullName" property of a file).
Have fun,
L.W.