Re: SAVED-property is true, but ... by Thomas
Thomas
Fri Feb 20 02:04:17 CST 2004
The code works, but I can't isolate the problem.
But if I close the document the msgbox is already shown.
thomas
"Peter Hewett" <Nospam@xtra.co.nz> schrieb im Newsbeitrag
news:Xns9495D2F7CAA73Iwlpth@207.46.248.16...
> 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
>
> "Thomas" <nix@Mail.de> wrote in
news:OF4kzM49DHA.1632@TK2MSFTNGP12.phx.gbl:
>
> > 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
> >
> >
> >
> > "Alex Ivanov" <consul@collegeclub.com> schrieb im Newsbeitrag
> > news:epweMYx9DHA.1268@TK2MSFTNGP12.phx.gbl...
> >> 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.
> >>
> >> "Thomas" <nix@Mail.de> wrote in message
> >> news:eT97D$u9DHA.2696@TK2MSFTNGP10.phx.gbl...
> >> > 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??
> >> >
> >> >
> >> > "Peter Hewett" <Nospam@xtra.co.nz> schrieb im Newsbeitrag
> >> > news:Xns9495194913C92Iwlpth@207.46.248.16...
> >> > > 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
> >> > >
> >> > >
> >> > > "Thomas" <nix@Mail.de> wrote in
> >> > news:e8oEasu9DHA.2644@TK2MSFTNGP11.phx.gbl:
> >> > >
> >> > > > 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?
> >> > > >
> >> > > > "Peter Hewett" <Nospam@xtra.co.nz> schrieb im Newsbeitrag
> >> > > > news:Xns94951348ED74AIwlpth@207.46.248.16...
> >> > > >> 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
> >> > > >>
> >> > > >> "Thomas" <nix@Mail.de> wrote in
> >> > > > news:eZWR5Tu9DHA.3428@tk2msftngp13.phx.gbl:
> >> > > >>
> >> > > >> > 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
> >> > > >> >
> >> > > >> >
> >> > > >> >
> >> > > >>
> >> > > >
> >> > > >
> >> > >
> >> >
> >> >
> >>
> >>
> >
> >
> >
>