Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-23-2013, 04:02 PM
Tang Tang is offline Word Crashing after VBA code runs successfully Windows 7 64bit Word Crashing after VBA code runs successfully Office 2007
Novice
Word Crashing after VBA code runs successfully
 
Join Date: Jul 2013
Posts: 1
Tang is on a distinguished road
Default Word Crashing after VBA code runs successfully

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
Reply With Quote
  #2  
Old 09-29-2013, 09:26 PM
macropod's Avatar
macropod macropod is offline Word Crashing after VBA code runs successfully Windows 7 32bit Word Crashing after VBA code runs successfully Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

When the code crashes, do you get an error message? Is a code line highlighted?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Crashing after VBA code runs successfully 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:23 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft