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!

Bringing Active Window to top...

Status
Not open for further replies.

ajharn

IS-IT--Management
Jun 8, 2002
71
US
Hi all...Please help...

I'm having trouble with the "Activate" method in VBA for Word 2000.

Scenario:
1) User starts Word. Word opens with a blank document.
2) User launches my Macro...
3) Macro opens a new document (based on a template) and adds some text to the new document.
4) The IP is set to a bookmark in the new document.

At this point, I want the new document to be brought to the top so the user will be presented with the prepared document. The existing blank document, if the user did not close it, is still on top, however.

Here are the methods I've tried, that don't seem to work.

1)ActiveWindow.Activate
--Placed this command right after the command that places the IP at the bookmark in the new document.
--Result: The Window is "Activated" (i.e. It's button is pressed in on the Task Bar, indicating that it is indeed the active window...but the non-active blank document is still "on top".

2)ActiveWindow.View
--Placed just below ActiveWindow.Activate statement above. Also tested by replacing the Activate statement with this statement.
--Result...same as above...window Activated but not brought to top.

3)Document.View...(tried this variation)
--Immediately after my Documents.Add statement that created the new document I used this statement:

strCurDoc = ActiveDocument.Name
I've tested this and it works...generally returns "Document2" or similar...always the matches the document that I've just created.
After I set the IP to the desired point in the new document, I then run this statement:

Documents(strCurDoc).Activate.

--Result: Same as all the above resluts. Activates window but does not bring to top.


Please help!!! I'm sure that there's a simple method that must accomplish this. I just can't seem to track it down in any literature.

I understand that I could close blank documents before the Macro executes to eliminate the clutter, but that is a workaround, not a solution. Also, a lot more work and not bulletproof.

Thanks in advance. Your help is severely appreciated.
 
ajhard,

To be honest, I haven't much experience with VBA for Word, but, won't the following work ? ...

Sub GoTo_NewFile()
Documents("newfile.doc").Activate
End Sub

This of course assumes (from your description) that YOU are opening and naming the new document.

Hope it helps. I'll be interested to know if it works :)

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Dale,

Thanks for the answer. As in my first note, I have tried opening the document then assigning the document name to a variable then using the document.activate method...as such:

Code:
 strCurDoc = ActiveDocument.Name
 Documents(strCurDoc).Activate

Again, when I do this, the window does not come to top, but it's task button on the task bar is pressed in and I can not perform any other action in any other window. So it is "Activated" per se, but not on top.

In this case, however, "I" have not named the document, as you suggest Word has..(usually, "Document1") or similar. Generally, at this point I haven't saved the document yet, and thus haven't assigned a name of my own to it. Is there away to assign a name to the document without saving it?

In the meantime, I will try saving it first, to see if it makes a difference. I'm not sure saving it first is viable in my current algorithm...but I want to know if it works!

Thanks for your input. Please let me know if you think I'm off base on anything here.

Thanks,
-AJ
 
only have Word 97 on this machine but you could try something like ...

[tt]Dim NewDoc As Word.Document

' create new document based on your template

Set NewDoc = Application.Documents.Add("C:\whereever\yourtemplate.dot")

' do other stuff here

NewDoc.Activate
[/tt]
 
Justin,

Thanks for the idea, I'll give it a shot.

I can't say my confidence is high though. This is just a weird deal. I'm not having trouble identifying the object to be activated...the activate method just seems to be behaving oddly. It "Activates" the window...but doesn't bring it to top.

I'll let you know how it goes.

Thanks,
AJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top