Getting rid of the Do You Want to Save Changes Box (1 Viewer)

aaronb50

Registered User.
Local time
Today, 15:19
Joined
Mar 2, 2014
Messages
185
I use the code below to take a preformatted word doc, open it, save some information to text boxes and then save a copy of it in a different folder.

Code:
 Dim appWord As Word.Application
 Dim doc As Word.Document
  
 On Error Resume Next
 Err.Clear
 'Set appWord object variable to running instance of Word.
 Set appWord = GetObject(, "Word.Application")
 If Err.Number <> 0 Then
 'If Word isn't open, create a new instance of Word.
 Set appWord = New Word.Application
 End If
  
 Set doc = appWord.Documents.Open("" & MSONewIssue & "", , True)
 With doc
 .FormFields("Text1").Result = Me.Text121.Value
.FormFields("Text2").Result = Me.Text124.Value
.FormFields("Text3").Result = Me.Text126.Value
.FormFields("Text4").Result = Me.Text130.Value
.FormFields("Text5").Result = Date
 .Visible = True
 .Activate
 
.SaveAs "" & Issue & ""
 .Close
 End With
 Set doc = Nothing
 appWord.ActiveDocument.Close
appWord.Quit
Set appWord = Nothing

And this works great except for the Microsoft Word box that asks:

Do you want to save changes you made to xxxxxxxxxxx.doc?

I think I attached an example of it.

Is there anyway to stop this box from coming up?

Its not happening in the original, that one closes with no issues. Its the .doc I save to the new folder that is bringing up the box.
 

Attachments

  • SaveBox.png
    SaveBox.png
    6.9 KB · Views: 116

aaronb50

Registered User.
Local time
Today, 15:19
Joined
Mar 2, 2014
Messages
185
So added that in and it was still coming up.

I put in a few Exit Subs to figure out just where it was happening and it looks like its actually happening on the next part when it prints a copy of the newly created document.

Code:
 Dim WordObj As Object
   Set WordObj = CreateObject("Word.Application")
   WordObj.Documents.Open "" & Issue & ""
   WordObj.PrintOut Background:=False
    WordObj.Quit
   Set WordObj = Nothing
Now I tried adding in that line: .Close wdDoNotSaveChanges

Code:
Dim WordObj As Object
   Set WordObj = CreateObject("Word.Application")
   WordObj.Documents.Open "" & Issue & ""
   WordObj.PrintOut Background:=False
   WordObj.Close wdDoNotSaveChanges
   WordObj.Quit
   Set WordObj = Nothing
But its still popping up.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 08:19
Joined
Jan 20, 2009
Messages
12,851
You are probably confusing the objects.

In your code WordObj is the application. That application has multiple document objects. You need to be careful which object you are referring to.
 

aaronb50

Registered User.
Local time
Today, 15:19
Joined
Mar 2, 2014
Messages
185
I got it!!

I added: WordObj.ActiveDocument.Close

Code:
Dim WordObj As Object
   Set WordObj = CreateObject("Word.Application")
   WordObj.Documents.Open "" & Issue & ""
   WordObj.PrintOut Background:=False
   WordObj.ActiveDocument.Close
   WordObj.Quit
   Set WordObj = Nothing


Thanks Galaxiom!!!!!!!
 

Users who are viewing this thread

Top Bottom