SAVED-property is true, but ...

T

Thomas

Hello

I use Word 2002 and load documents in the internet explorer 6. (like
file:\\C:\test.doc)
This is not really a problem. My problem is this:

In my document are a lot of fields. I unlink the fields with vba and print
the document. After this, i set the saved - property "TRUE" and would close
the document. Befor the document closed, word ask me: "Would you save the
changes?" What is this?? The saved - property is TRUE and word ask me to
save changes? I don't know where the problem is ...

Can someone help me ???

Thomas
 
P

Peter Hewett

Hi Thomas

Read the message carefully is it asking you to save the changes to the
document or the template? If it's the template then you obviously need to
either save the changes or ignore the changes.

HTH + Cheers - Peter
 
T

Thomas

It is asking to save the changes to the document and not to the template.

i would like to close the document without any savequestion from word. But
the property document SAVED set on TRUE is not anouth.

What can I do? How I can make that?
 
P

Peter Hewett

Hi Thomas

The code to stop Word from prompting to save the changes to your document
is:

ActiveDocument.Saved = True

I can think of a number of reasons that this code does not do what's
expected:

1. The document is updated again before it's closed
2. The document you are closing is not the ActiveDocument at the time the
above code is run
3. Are you actually executing the above code

also when you close the file, use something like:
ActiveDocument.close wdDoNotSaveChanges

HTH + Cheers - Peter
 
P

Peter Hewett

Hi Thomas

Sorry 3 should have read "You are NOT actually executing the above code"

Cheers - Peter
 
T

Thomas

I know that is the right file (activedocument) and the document is not
change before closing. Because the document is the only one in the
application.

I close the document with "activedocument.close wddonotsavechanges". It work
But i can't close the document in the internet explorer. The error
description is "document is open in an other application".

It works in word but not in an other application where you use the
documentobject. have you for thes problem some ideas??
 
P

Peter Hewett

Hi Christian

Although "ActiveDocument.Close savechanges:=False" works the preferred method
is:

ActiveDocument.Close wdDoNotSaveChanges

This is because the SaveChanges argument is an Enum (an enumerate type) with
3 values: wdDoNotSaveChanges, wdPromptToSaveChanges or wdSaveChanges.

For compatibility with future versions of Word it's always worth doing it the
correct way, it eliminates opportunities for bugs to creep in.

Cheers - Peter
 
A

Alex Ivanov

I think you have a mistake somewhere creating/destroying the document
object.
A snippet of your code would perhaps help to identify the problem.
A common mistake that leads to similar behavior is to have two object
variables that physically refer to the same object, but logically are not
the same. For example,
Set wdApp=CreateObject("Word.Application")
Set Doc=wdApp.Open("AnyDocument.doc")
wdApp.Activedocument.Saved=True ' Oops! ActiveDocument is not the same
logical object as Doc!
' It is an automatic variable you have just implicitly created.
ActiveDocument is Saved, Doc may be not!
Doc.Application.Close ' Again, you created a new instance of an Application
object here, it is not exactly the same as wdApp.

HTH,
Alex.
 
T

Thomas

No, it is not a mistake. The problem can always reproduced in the IE 6. I
load the document, push the button und close the document. All what I do in
the Document is unlink all the fields. The last activity in the code is to
set the SAVED property of the activedocument. Then I change the URL like
"about:blank" to unload (clouse) the document. So you can see it isn't a
mistake with the object.

and this is the code which is run in the document

Sub FieldsUnlink()

' Unlink fields
ActiveDocument.Fields.Unlink

' clean header
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = False Then _
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

On Error Resume Next
Do
Selection.WholeStory
Selection.Fields.Unlink
ActiveWindow.ActivePane.View.NextHeaderFooter
Loop Until Err.Number <> 0
' breakpoint is the errornumber 4605

' RESET
Err.Clear

' change to footer
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then _
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

' clean footer
Do
Selection.WholeStory
Selection.Fields.Unlink
ActiveWindow.ActivePane.View.NextHeaderFooter
Loop Until Err.Number <> 0

' back to the main doc
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

' change the property
ActiveDocument.Saved = True

MsgBox "SAVED-property --> " & ActiveDocument.Saved

End Sub
 
P

Peter Hewett

Hi Thomas

Try this alternative code, I've posted 3 procedures. The shortest
(UnlinkAllFields) unlinks all fields anywhere in the document! The other 2
will unlink Header/Footer fields:

Public Sub UnlinkAllFields()
Dim lngJunk As Long
Dim rngStory As Word.Range

' Word missing first Header/Footer bug workaround
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType

' Iterate through all story types in the current document
For Each rngStory In ActiveDocument.StoryRanges

' Iterate through all linked stories
Do
' Do Update all fields
rngStory.Fields.Unlink

' Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
End Sub

Sub UpdateFieldsInHeaders()
Dim Story As Word.Range
Dim rngNext As Word.Range

' Iterate through all story types
For Each Story In ActiveDocument.StoryRanges

' Only update fields in a header
If Story.StoryType = wdPrimaryHeaderStory Or _
Story.StoryType = wdFirstPageHeaderStory Or _
Story.StoryType = wdEvenPagesHeaderStory Then

' There may be linked headers so update
' any fields in them as well
Set rngNext = Story
Do Until rngNext Is Nothing

' Update fields in this header
rngNext.Fields.Update

' Link to next story (if any)
Set rngNext = rngNext.NextStoryRange
Loop
End If
Next
End Sub
Sub UpdateFieldsInFooters()
Dim Story As Word.Range
Dim rngNext As Word.Range

' Iterate through all story types
For Each Story In ActiveDocument.StoryRanges

' Only update fields in a footer
If Story.StoryType = wdPrimaryFooterStory Or _
Story.StoryType = wdFirstPageFooterStory Or _
Story.StoryType = wdEvenPagesFooterStory Then

' There may be linked footers so update
' any fields in them as well
Set rngNext = Story
Do Until rngNext Is Nothing

' Update fields in this footer
rngNext.Fields.Update

' Link to next story (if any)
Set rngNext = rngNext.NextStoryRange
Loop
End If
Next
End Sub

This code also avoids all the window switching. At the very least it should
enable you to isolate the problem.

HTH + Cheers - Peter
 
T

Thomas

The code works, but I can't isolate the problem.
But if I close the document the msgbox is already shown.

thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top