Results 1 to 11 of 11
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Boston, Massachusetts, USA
    Posts
    205
    Thanks
    0
    Thanked 0 Times in 0 Posts

    set focus (VBA/Word2000)

    I have a form set up to create a special mailing label. The code uses
    set docNewDoc = Documents.add
    then uses a with statement to set formatting.
    However, using the documents.add creates a new document, and sets up the formatting and everything fine. Except that after the form unloads, and everything is done, the document with the mailing label is not the document visible on the screen. I remember at one time using set focus to make the document created the one that is active. Can anyone remember off the top of their heads how to use set focus????

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

    Re: set focus (VBA/Word2000)

    G.F.,

    docNewDoc.Activate

    should do it.

    Gary

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Boston, Massachusetts, USA
    Posts
    205
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: set focus (VBA/Word2000)

    I tried it thinking for sure that it would work! Not quite.

    When the form has unloaded, the task bar at the bottom of the screen has document 2 clicked off, but what is actually visable on the screen is document 1.

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: set focus (VBA/Word2000)

    Maybe this will work for you :-

    Application.Windows(docNewDoc).Activate
    ActiveWindow.SetFocus

    Andrew C

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Boston, Massachusetts, USA
    Posts
    205
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: set focus (VBA/Word2000)

    That did it. Thanks so much!

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

    Re: set focus (VBA/Word2000)

    Worked for me too! Just what I've been looking for all these months, and so simple!

    Thanks.

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

    Re: set focus (VBA/Word2000)

    Thanks Andrew - I'm going to use this too!

    After looking at this code for a while, I started to wonder why it doesn't cause a type mismatch error: since docNewDoc is an object variable that points to a document object - how can a document object be specified as an index value? For example, VBA help says:

    "Use Windows(index), where index is the window name or the index number, to return a single Window object."

    A document object is neither a name nor a number - you'd think at least "docNewDoc.Name" is required - i.e. a string rather than an object.

    Well, it turns out that "Name" is the default property of the Document object. So somehow VBA is smart enough to know that if it is supplied an object where it expecting a string, it should look at the object's default property, before giving up and causing an error. But still, if you specify a document object in a context that requires a document object, it interprets that as an object. (And that raises the question: just what is stored in an object variable? - maybe a document object variable simply stores an indicator of the type of object plus its name - so that when you use "docNewDoc" this gets interpreted as Documents(docNewDoc.Name)?) I guess I don't really know what an object variable really stores - anyone out there care to take a swing at this?

    Gary

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: set focus (VBA/Word2000)

    Gary,

    An Object Variable is nothing more than a pointer (32 bit memory address) to the memory area where the object data is stored. I suppose any reference to Object Variable is much the same as a referring to it by name.

    Andrew

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: set focus (VBA/Word2000)

    I think it's more like pointing at the object and saying "that one, over there". Even when you refer to an object by name, that's essentially what you're doing, pointing to the instance of the object.
    Charlotte

  10. #10
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: set focus (VBA/Word2000)

    Right Charlotte, that is more or less what I was trying to say, but as usual you articulated it more eloquently.

    Andrew

  11. #11
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: set focus (VBA/Word2000)

    <img src=/S/blush.gif border=0 alt=blush width=15 height=15> Thanks.
    Charlotte

Posting Permissions

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