activating window by number in windowlist problem

  • Thread starter charlie.planetxsolutions
  • Start date
C

charlie.planetxsolutions

i'm working with the following piece of code that is supposed to go through
all open word documents and close those that do not have a specific title
property. this code has worked in the past but now has stopped functioning.

For iWNum = 1 To iMAX_ARRAY_SIZE

If iWNum > WordBasic.CountWindows() Then
GoTo EndofSub
End If


' Activate window and get keyword property setting
WordBasic.WindowList iWNum
sKeyWord$ = WordBasic.[GetDocumentProperty$]("Keywords")

' If not the template, create document or missing provision window
If sKeyWord$ <> sTemplateFilePropertyTitle$ Then
If sKeyWord$ <> sCreateDocumentFilePropertyTitle$ Then
If sKeyWord$ <> sMissingProvisionsFilePropertyTitle$ Then
If sKeyWord$ <> sNonCheckingCopy$ Then
WordBasic.DocClose 2 'close window, do not save
iWNum = iWNum - 1 'decrement window count
End If
End If
End If
End If

Next iWNum

personally, its not a very nice way to do things and the best implementation
is probably to use 'for each doc in documents' which i have tested and works
great.

what happens with this code is that when keeping track of the document via
windowlist then the document windows change subscript.

my question is, was there a recent change in how windows treats
'WordBasic.WindowList iWNum' that would account for this apparent change in
behavior? is it purely luck that this code has worked in the past?

any information would be greatly appreciated.
 
H

Helmut Weber

Hi Charlie,

if your code has been working so far,
I think, you were lucky.

First, closing windows is different from closing documents,
as a doc can have two windows.

Then you don't need to active a window at all,
if you loop through des documents' collection, like:

Sub test00000()
Dim oDcm As Document
For Each oDcm In Documents
With oDcm.BuiltInDocumentProperties ' probably
' as I don't remeber what "wordbasic keyword" was
If .Item("Title").Value <> "MyTitle" Then ' e.g.
oDcm.Saved = True
oDcm.Close
End If
End With
Next
End Sub

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
C

charlie.planetxsolutions

thanks helmut!

greetings from victoria, british columbia, canada
 

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