As an addendum, I've managed to come up with the below, which basically copies the contents of the opened document into a new blank word doc, performs the operations on this new document, and saves it with a new filename in the same folder. The original document is not closed, as the problem occurs when the macro tries to save and close the original. It's not ideal, but it does show that the macro has no problems saving and closing documents which were not created via a mail marge
Ganet
Macro Code
Sub M_process_many_files(
' InsertFileNames Macr
' Macro created 08/07/97 by Jim Chevallie
'Edited 6.2.04 by gareth.dar
'Assign the values of Word's File Find (Search) dialogue box to 'mydialog
Set mydialog = Dialogs(wdDialogFileFind
'Assign certain info from the dialogue box to variable
'(This will pick up whatever you set when you went into File Open
's$ = mydialog.SearchPat
N$ = mydialog.Nam
'Assign the more generic Application.FileSearch to the 'Fs' variabl
Set Fs = Application.FileSearc
'Use the With instruction to work with Fs as the implied high-level qualifie
' (i.e., Fs.Lookin, Fs.MatchTestExactly, etc.
With F
'Assign the values captured from WdFileFind to the Application.FileSearch Variable
'MsgBox mydialog.SearchPat
where = InputBox("where"
Application.FileSearch.LookIn = wher
Application.FileSearch.FileName = N
'Set other parameters for Application.FileSearc
Application.FileSearch.MatchTextExactly = Tru
'Application.FileSearch.FileType = msoFileTypeAllFile
Application.FileSearch.FileType = msoFileTypeWordDocument
Application.FileSearch.SearchSubFolders =
'Test if the execution was successfu
If .Execute() > 0 The
'Using a 'For' loop, go through the found file
For i = 1 To .FoundFiles.Coun
Documents.Open FileName:=.FoundFiles(i), ConfirmConversions:=False,
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
WritePasswordTemplate:="", Format:=wdOpenFormatAut
'Do somethin
'MsgBox "Opened" + .FoundFiles(I
do_it = "y
'do_it = InputBox("Process this document? Default = 'y', no = 'n'", "Process this document", "y"
If do_it <> "" The
If do_it = "y" The
Application.Run MacroName:="zz_open_copy_save_and_close
'Save and clos
'ActiveDocument.Sav
'ActiveDocument.Clos
End I
End I
Next
'If execution was not successful, display a messag
Els
MsgBox "There were no files found.
End I
End Wit
End Su
Sub zz_open_copy_save_and_close(
' zz_open_copy_save_and_close Macr
' Macro recorded 09.02.2004 by gareth.dar
Selection.WholeStor
Selection.Cop
newname = Replace(ActiveDocument.FullName, ".doc", "new.doc"
Documents.Add DocumentType:=wdNewBlankDocumen
Selection.Past
Application.Run MacroName:="F_page_margins
ActiveDocument.SaveAs FileName:=newname, FileFormat:=
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:=
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=
False, SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:=Fals
ActiveWindow.Clos
End Sub