Word 2003 ActiveDocument.Name

H

HHDM

Hi group

I have a macro that uses the ActiveDocument.Name property, but it seems
that when I create a new document based on the template that holds this
macro, the new document is not always the active document.

I would assume that when you create a new document, this would
automatically be set as the active document, but I can see it happens
many times, that the new document it placed behind one or more documents
currently opened in Word, and one of these is the active document
instead of the newly created one.

How can I force the newly created document always to be the active document?

Best regards
Hans-Henrik
 
D

David Sisson

Dim MyDoc1 As Document

Set MyDoc1 = Documents.Add()

Now, MyDoc1 is set as a object and you can access it without having to
make it active.

Or, if you must have it active, MyDoc1.Activate
 
H

HHDM

David Sisson skrev:Yes, but this will add an extra document - what I want to do is, make a
new document based on a specifik template, that already contains some
text, and I want the newly created document to be the active one, which
it not always is, as previously described.

If I use Documents.Add() - I'll get an extra document.

I would like to be able to select Files -> New
Then select template and go
 
R

Russ

Read this message thread about open document events.
It sounds like you want to put your activate command in the
Document_Open()
ThisDocument.Activate
End Sub
event of the ThisDocument module of the template.
http://tinyurl.com/2zkoax
 
D

Doug Robbins - Word MVP

Take the time to look at the .Add function for the Document object in the
Visual Basic Help File and all will be revealed.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
H

HHDM

Thanks Russ

You got me on the right track

I now use the Document_New()

then use a public variable:

documentname = ActiveDocument.Name

and I can then use Documents(documentname).Activate where appropriate
 

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