Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Wd2K - Document New/Active Document

    Help!!
    I have a set of templates that all contain code activated when the user does a File New. In the ThisDocument area I have a Document_New that runs a form and fills in all the details - beautiful, until....

    If I have a document on the screen that has been created based on a template, and then try and create another document, two things happen. First, a new document is created, but not made active. Second, the original document is then modified by the form and the changes saved.

    What I believe should happen is that on File New, the new document is made active, and any procedures that modify the document (eg filling in data for a letter and naming and saving the letter) should be applied to that new document - not another document that happens to be on the screen at the same time!

    Word 97 doesn't appear to have this problem and I think it has something to do with the activedocument.

    I also have a problem when a user tries to print using printing macros. The user obviously wants to print what he or she can currently see on the screen (what I would expect to be the active document). However Word 2K doesn't always agree that that is the active document, and often prints another of the open documents.

    In the past I put all the code into a master template that was stored in the startup directory. However, this master template became too big and unwieldy. It was easier to break it up into smaller chunks and code that was specific to a template was stored on that template, only shared code stored on the master template. I would like to keep it this way if possible.

    Any ideas would be most welcome.

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wd2K - Document New/Active Document

    Karen,

    I haven
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Wd2K - Document New/Active Document

    My Lifesaver!!!! Such a simple thing to do too, so now I have changed all my Word 2K templates and am getting my users to test them (no matter how much I test I find the users always do something I hadn't thought of!)

    It seems to be the order in which documents are loaded - the first one appears to be the active document, the next loaded is active for the time of its loading and then the first becomes active again! Does anyone else think that Microsoft stuffed up here?

    Thanks very much Geoff

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Wd2K - Document New/Active Document

    Hi Karen,

    We have lots of Word 97 templates that we're in the process of moving over to Word 2000 - many of these have userforms that do all sorts of processing in the course of creating the new document.

    They all are working fine, though, in terms of the newest document always becoming the active document - we didn't have to change these in moving from 97 to 2000.

    The only place where I ran into a couple of problems was in procedures that do a lot of switching windows - as Geoff described - and as Geoff described, the solution is to set object references to each of the documents and then refer to them specifically as needed later.

    Could it be that something in your "new document" process is switching windows or views in some way, to trigger the problem?

    Gary

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Wd2K - Document New/Active Document

    Hi Gary
    Congrats on your WMVP status by the way!
    As for switching windows or views I don't really think so. I use the Document_New() to fire up a form that then simply uses the ActiveDocument command, eg ActiveDocument.Bookmarks("Recipient").Select, to do something.

    I also have a procedure for printing to a digital printer that simply uses the ActiveDocument to set up the paper source for each section in the document. Before putting in the solution suggested by Geoff, if you had more than one document open the procedure would not print the document you could see on the screen, rather it would print the first document you had opened. This was also a problem with a Name and Save Document procedure that we use to do a File Save As - if you had more than one document open it would not Name and Save the document that was visible on your screen - rather one of the documents in another window. This routine did go into the header/footer to put a code identifying the document (not usually the entire filename)

    Never had these problems with 97! However, I love having more than one item on the taskbar to identify what documents I have open.

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Wd2K - Document New/Active Document

    Hi Karen,

    Thanks!

    It sounds like the types of things you're doing shouldn't cause a problem. Hmm, someday we're going to have to figure out why the ActiveDocument scrambling is happening on some Word 2000 installations and not others. It's probably good practice to set references to the documents, rather than use ActiveDocument, anyway.

    As to the taskbar, having had to wait months to get onto 2000, I'd heard so much about the SDI issue I wasn't looking forward to it. But in most respects it's pretty functional.

    I did have to give up one favorite trick, though: in Word 97 I had a couple of procedures that did lengthy processing in an existing document - to keep the users from worrying, and to keep them from touching the keyboard (and to keep them entertained), I would keep the userform visible while the procedure ran, minimize the ActiveDocument, and send progress updates to the user via the userform. And when the procedure was finished, the userform would disappear and the document would pop back up to maximized. This all provided some fun animation for a boring operation.
    Because of the MDI, the user would only see the userform against a gray background (could only do this trick with one document open).

    In Word 2000, without the MDI, you can't expose the gray background. I had to settle for zooming the document down to about 60% and then restoring it to full size when done - not quite as flashy.

    Gary

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Wd2K - Document New/Active Document

    We're running Office from our local pcs, Windows 2000, and exchange server.

    Provides a bit of stress to life anyway!!

  8. #8
    DSteiNeuro
    Guest

    Re: Wd2K - Document New/Active Document

    "What I had to do in that circumstance was to store the activedocument name in a variable when I created the new document; and then activate it (again) every time I needed to do something on the activedocument."


    Can you explain this in a little more detail.

    Thanks

  9. #9
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wd2K - Document New/Active Document

    Hi,

    Stretching the memory banks a little here!

    The code would look like this:

    Dim strActiveDocName As String
    Documents.Add
    strActiveDocName = ActiveDocument.Name

    ...

    Documents(strActiveDocName).Activate
    Activedocument.DoSomething
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  10. #10
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Wd2K - Document New/Active Document

    You can do it even more simply (note: I've added a few extra statements just to flesh out the demo):

    Sub ActivateDoc()
    Dim objDoc1 As Document
    Dim objDoc2 As Document

    Set objDoc1 = Documents.Add
    objDoc1.Range.Text = "This is document 1!"

    'adding a second doc, just to demo activating doc 1 again:
    Set objDoc2 = Documents.Add
    objDoc2.Range.Text = "This is document 2!"

    objDoc1.Activate

    End Sub

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wd2K - Document New/Active Document

    Hi Karen:

    This is a old thread, but I wonder if there's anything in Windows behavior that affects the active document. I know that in the Tweak UI/General tab dialog box, there is a checkbox for "Prevent applications from stealing focus". I have it ticked on my machine. I have no idea whether that will make any difference (& by now you've probably modified all your templates), but I thought I'd mention it for what it's worth.

  12. #12
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Wd2K - Document New/Active Document

    Where is this Tweak UI/General dialog to be found?

  13. #13
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wd2K - Document New/Active Document

    <P ID="edit"><FONT SIZE=-1>Edited by Phil Rabichow on 01/03/19 03:18.</FONT></P>Hi Karen:

    You can download it from an unlikely spot, since it works for Win95 & Win 98. Latest version is 1.33 at

    <A target="_blank" HREF=http://www.microsoft.com/ntworkstation/downloads/powertoys/networking/nttweakui.asp>http://www.microsoft.com/ntworkstation/dow...g/nttweakui.asp</A>

    It is definitely worthwhile, as you can change many windows features without having to edit the registry.

    Cheers!

  14. #14
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Wd2K - Document New/Active Document

    Thanks Phil. I'll try it out. I have modified most of my templates, but some of the other options could be useful.

  15. #15
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wd2K - Document New/Active Document

    It's so reassuring to see that Karen has done or is trying to do the same things I've been trying to do. I've had the problem in Office 97, though, on NT. I'm using Karen's code to open a new document from a template when the template name is clicked in Word. (I'm using a shortcut to accomplish this from a browser, but it occurred to me I could do both, so a new document would open whether from the browswer or from Word).

    I tried Geoff's suggestion, but it still left the original document (the one with the link) on top. It seems to think the one that's on top is the current document, so if you save the name of the current document to activate it, that's the one you get.

    I tried Gary's suggestion to incorporate setting the new object in the add statement, but I specify the template and there's a compile error - expected end of statement. The statement is:

    Set objDocNew = Documents.Add Template:="J:PROJ-CORTemplateUpdatesProject97ProjectDataelem.dot", _
    NewTemplate:=False

    It highlights the word 'Template' as the problem. Do you know what I'd need to change?

    Phil, I can't use a solution that depends on a machine setting, as these templates are used by lots of machines on a LAN.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •