Can I control the sequence of Word document windows?

H

headly

Writing some code where a template opens another template to share data from
forms. It's easy to control window activation when you know there are only
two windows open. But when I try to capture the number of open windows and
work from there, I noticed that word will alphabetize the list of windows. So
if my template creates documents1 and documents2, i'm okay if there are no
other windows open. If other windows are open and they have names from
e-zdocument, it throws off my window counting against words alphabetical
window sequencing. Ideas?
 
P

Perry

To activate a document from within code, I wouldn't use the Windows()
function to return
a particular document.

I would use object variables of documents you instantiated in code, like:

Dim oDoc_Offer As Word.Document
Dim oDoc_Finalize As Word.Document
Dim oDoc_Invoice As Word.Document

Set oDoc_Offer = Documents.Add("c:\MyPath\Offer.dot")
Set oDoc_Finalize = Documents.Add("c:\MyPath\Finalize.dot")
Set oDoc_Invoice = Documents.Add("c:\MyPath\Invoice.dot")

oDoc_Finalize.Activate
'regardless how many windows are open, the correct document will be
activated
'without having to run/loop through the windows collection...

Krgrds,
Perry
 
H

headly

Thanks for your thoughts Perry. I can see how this can help in one subroutine
but after the documents are open, how do I tell other subroutines in my
module about those object declarations?
 
P

Perry

Pass the object variable as a parameter to the subroutine

Example:

Sub MySubRoutine(ByVal InvoiceDoc As Word.Document)
'do your stuff here
End Sub

Calling the subroutine from another routine wud sound like:

Sub OtherRoutine()
Dim oDoc_Invoice As Word.Document
Set oDoc_Invoice = Documents.Add("c:\MyPath\Invoice.dot")
'<< do some stuff here to the document

'<< this is where you call a subroutine, note the parameter
MySubRoutine oDoc_Invoice

End Sub

Krgrds,
Perry
 

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