Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switching between active Word documents

Status
Not open for further replies.

furtivevole

Technical User
Jun 21, 2001
84
GB
Hopefully a simple answer!

I am running a macro from a mailmerge document (let's call it A) that generates a formletters document (let's call it B). The macro has to reformat data in B, copy it to clipboard, then return focus to A.

I assume that I therefore need to make B temporarily the active document.

Neither "A" nor "B" can be hardcoded, but full path names are held as global variables.

What's the best means of switching between one and the other? It's possible that the user could have other docs open concurrently, so (unlike a recent posting on this subject) I can't reply on a simple Windows(1) and Windows(2).

TIA, Linnet

 
If you have the full path name, then, on opening, can you not call the activedocument.name - assign to a variable and use that to switch
HTH
Geoff
 
Geoff

That was one approach I was hoping to use - just getting stuck on syntax.

Linnet
 
why not try something like this

Dim docA As String

docA = ActiveDocument.Name

this will set the variable docA = the name of the document current active document, then open the next document and do the same with a seperate variable. You should then be able to work with them going forward

Andy
 
Thanks for the feedback.... Somehow I havn't completely conveyed the problem.

I have docA & docB dim'd as strings already.

I want to be able to do something like:

Code:
Windows(n).activate

where n is the correct integer for a specific document (remembering that there may be other unrelated docs open concurrently). So how is the value of n identified using docA? (Assuming there isn't a better approach.)




 
I found this in the help file, do they help?


Andy

This example returns the number of the first window in the Windows collection. If there are at least two windows in the Windows collection, the macro activates the next window, copies the first word, switches back to the original window, and inserts the Clipboard contents there.

Set myWindow = Windows(1)
winNum = myWindow.Index
If Windows.Count >= 2 Then
myWindow.Next.Activate
ActiveDocument.Words(1).Copy
Windows(winNum).Activate
Selection.Range.Paste
End If
 
Linnet,

Following up on Geoff and Andy's suggestion, you should be able to use the following:

Code:
Windows(DocA).Activate

assuming you've assigned
Code:
Activedocument.Name
to DocA as posted. It's always better to use explicit names rather than indexes.


HTH

M. Smith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top