Group: microsoft.public.word.vba.general
From: BHW
Date: Tuesday, March 25, 2008 3:11 PM
Subject: Re: Macro to open new document and then switch back to old doc, word20

Jay,

Thank you so much! I will study this and apply it. This is great.

Thanks again - very generous of you.

Bruce

On Jan 26, 1:30 am, Jay Freedman wrote:
> On Fri, 25 Jan 2008 16:44:00 -0800, Alan Stancliff
>
> wrote:
> >Is it possible to write a macro that does the following:
> >1. Notice what document the cursor is in
> >2. Open a new document. Perform some task there
> >3. Close the new document without saving.
> >4. Go back to the document that was active when the macro began
>
> >Regards,
>
> >Alan
>
> Sub demo()
> Dim firstDoc As Document
> Dim secondDoc As Document
>
> ' remember where you parked the car
> Set firstDoc = ActiveDocument
>
> ' make a new doc based on Normal.dot,
> ' which automatically becomes active
> Set secondDoc = Documents.Add
>
> ' do some work in secondDoc
> secondDoc.Range.Text = "Hello Word"
>
> ' close without saving
> secondDoc.Close SaveChanges:=wdDoNotSaveChanges
>
> ' firstDoc probably becomes active here,
> ' but if not then force it
> firstDoc.Activate
> End Sub
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ:http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.