Return to the previous document

G

GoldenPenny

I am trying to write a macro where I start from an open document. Then I
open another document containing a grid that must be inserted into the first
document. I copy the grid and return to the first document, paste the grid,
then close the document containing the grid.
My problem is returning to the first document. When I use the macro
recorder, the line reads:
Windows("Document2").Activate
The document I want to return to is not necessarily name "Document2".
How do I return to whatever the original document is?
Thanks so much.
 
H

Helmut Weber

Hi GoldenPenny,

one of several ways.
create a document object and assign the now active document to it,
like
dim firstdoc as document
set firstdoc = activedocument ' the document the macro starts from
' do something
firstdoc.Activate

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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