Hi
I've got a macro that creates a series of folders then opens a series of dotx word templates and then saves them to the folders that have been created. This has been working fine, but now seems to have hit a problem where some of the documents open but don't save automatically to the folder and instead prompts the user to save which causes the code to bomb out.
Would anyone be able to point out how I could improve my code to prevent this, its quite long so I've only posted the section with the word document creation loop. I've got option explicit at the top and all my variables are ok. Any pointers in sorting this is much appreciated.
I've got a macro that creates a series of folders then opens a series of dotx word templates and then saves them to the folders that have been created. This has been working fine, but now seems to have hit a problem where some of the documents open but don't save automatically to the folder and instead prompts the user to save which causes the code to bomb out.
Would anyone be able to point out how I could improve my code to prevent this, its quite long so I've only posted the section with the word document creation loop. I've got option explicit at the top and all my variables are ok. Any pointers in sorting this is much appreciated.
Code:
'open templates, populate and save
x = 0
'intFoundFileswd is total number of word templates to run
Do Until x = intFoundFileswd
' this is the save name
WdTemplate = Left(FileListwd(x), Len(FileListwd(x)) - 5)
With wApp
Set wDoc = wApp.Documents.Open(strFolder & FileListwd(x))
'pre populate some info into doc fields
With wDoc
.BuiltinDocumentProperties("Title").Value = Title
.BuiltinDocumentProperties("Manager").Value = Manager
.BuiltinDocumentProperties("Subject").Value = Reference
If InStr(WdTemplate, "Checklist") > 0 Then
.SaveAs Filename:=strNewProjectFolder & SubFolder & FolderReference & "\1. Checklists\" & Reference & "-" & WdTemplate, FileFormat:=wdFormatXMLDocument, AddtoRecentFiles:=False
ElseIf InStr(WdTemplate, "Assessment") > 0 Then
.SaveAs Filename:=strNewProjectFolder & SubFolder & FolderReference & "\2. Gateway Assessments\" & Reference & "-" & WdTemplate, FileFormat:=wdFormatXMLDocument, AddtoRecentFiles:=False
ElseIf InStr(WdTemplate, "Meeting") > 0 Then
.SaveAs Filename:=strNewProjectFolder & SubFolder & FolderReference & "\5. Project Meetings\" & Reference & "-" & WdTemplate, FileFormat:=wdFormatXMLDocument, AddtoRecentFiles:=False
Else
.SaveAs Filename:=strNewProjectFolder & SubFolder & FolderReference & "\4. Project Documents\1. Project Management Documents\" & Reference & "-" & WdTemplate, FileFormat:=wdFormatXMLDocument, AddtoRecentFiles:=False
End If
End With
End With
Set wDoc = Nothing
x = x + 1
Loop
wApp.Quit