• set focus (VBA/Word2000)

    Author
    Topic
    #358429

    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????

    Viewing 0 reply threads
    Author
    Replies
    • #534832

      G.F.,

      docNewDoc.Activate

      should do it.

      Gary

      • #534836

        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.

        • #534860

          Maybe this will work for you :-

          Application.Windows(docNewDoc).Activate
          ActiveWindow.SetFocus

          Andrew C

          • #534861

            That did it. Thanks so much!

          • #535564

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

            Thanks.

          • #535580

            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

            • #535743

              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

            • #535747

              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.

            • #535786

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

              Andrew

            • #535828

              blush Thanks.

    Viewing 0 reply threads
    Reply To: set focus (VBA/Word2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: