![]() |
|
|
|
#1
|
|||
|
|||
|
I have created a vba macro to streamline a process at work. The Macro works, but once it is done if I try to open another .docm file (in the same word session) it crashes. I believe it has something to do with my code in the "Else" section since it will open the file fine in the "If" section, but I can not figure it out.
Below is my code. I'm hoping one of you can see what is causing this. Code:
Sub Save()
'Check if File exists
If Dir("\\cssshare01.nwie.net\itsd\Specialists\Chat Review\" & ActiveDocument.FormFields("Manager").Result & "\" & ActiveDocument.FormFields("Date").Result & ".docm") = "" Then
ActiveDocument.SaveAs "\\cssshare01.nwie.net\itsd\Specialists\Chat Review\" & ActiveDocument.FormFields("Manager").Result & "\" & ActiveDocument.FormFields("Date").Result & ".docm"
Documents.Open ("\\cssshare01.nwie.net\itsd\Specialists\Chat Review\Monthly Chat Review Template.docm")
Documents(2).Activate
ActiveDocument.Close
Else
ActiveDocument.Unprotect 'Unprotect Template
Selection.WholeStory 'Select all in template
Selection.Copy 'Copy all in template
'Open existing file
Documents.Open ("\\cssshare01.nwie.net\itsd\Specialists\Chat Review\" & ActiveDocument.FormFields("Manager").Result & "\" & ActiveDocument.FormFields("Date").Result & ".docm")
'Unprotect Existing
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then ActiveDocument.Unprotect
Selection.EndKey Unit:=wdStory 'Move to end of existing
Selection.InsertBreak Type:=wdPageBreak 'Insert page break in existing
Selection.Paste 'Paste to existing
ActiveDocument.Save 'Save Existing
Documents(2).Activate 'Activate Template
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges 'Close Template
ActiveDocument.Close 'Close Existing
Documents.Open ("\\cssshare01.nwie.net\itsd\Specialists\Chat Review\Monthly Chat Review Template.docm") 'Open Template
End If
End Sub
|
|
#2
|
||||
|
||||
|
When the code crashes, do you get an error message? Is a code line highlighted?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Word form - created successfully, problem filling out
|
Bibi_D | Word | 2 | 07-29-2013 01:53 AM |
| EndNote Crashing Word | judicial85 | Word | 0 | 02-06-2012 06:23 AM |
| VB code from one document runs on other open documents | beav_35 | Word VBA | 0 | 11-10-2010 02:52 PM |
| Word :mac 2008 is crashing all day long... | P. Alkuin | Word | 4 | 04-20-2010 10:47 PM |
| Word 2003 Crashing | rjh500 | Word | 1 | 02-10-2010 07:39 AM |