Consulting

Results 1 to 19 of 19

Thread: Place Cursor At End Of Message

  1. #1

    Question Place Cursor At End Of Message

    Ok, so I'm able to get my template placed in correctly with the look I want when a user presses a button. Only problem is that after the code is added, the message box is at the top of the message. I'd like to be at the bottom of the message (where the new template has been inserted) and even better if the focus is in the Message with the cursor at the end. The only method that I've seen for this is Activate, but I can't find an Inspector for the actual message box, just the Message tab. Any ideas?

    Thanks again,
    Doug

  2. #2
    VBAX Tutor SJ McAbney's Avatar
    Joined
    May 2004
    Location
    Glasgow
    Posts
    243
    Location
    I've never seen any coding in Outlook but, if it is like other Office applications in its usage of VBA then you should look up the SelStart proeprty.

  3. #3
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    Here is some code that will place the insertion point at the end of the text in a textbox

    [vba]
    TextBox1.SelStart = TextBox1.TextLength
    TextBox1.SetFocus
    [/vba]
    "All that's necessary for evil to triumph is for good men to do nothing."

  4. #4
    Can't get that to work in Outlook with the Message Body.

    Still looking for a solution.

  5. #5
    VBAX Regular
    Joined
    May 2004
    Location
    Paris, France
    Posts
    6
    Location
    DLancy,
    I do not really understand what you want to do.

    What do you call the message box? msgbox or the message body?
    I am afraid you cant set the insertion point in a message body unless you are using Word as editor (dreamboat: what about inserting somewhere in the text?)

    Stefri

  6. #6
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Yeah, we can do end of story in Word...

    [vba]Selection.EndKey Unit:=wdStory[/vba]

    Thanks for stopping in, Stefri!!
    ~Anne Troy

  7. #7
    Well, I've finally got it to focus into the message of the form, but I haven't found a way to move it to the end yet.

    Thanks for the continued help.

    -Doug

    [VBA]
    sub CommandButton_click()
    Set objPage = Item.GetInspector.ModifiedFormPages("Message")
    Set objControl = objPage.Controls("Message")
    objControl.SetFocus
    end sub
    [/VBA]

  8. #8
    VBAX Regular
    Joined
    May 2004
    Location
    Paris, France
    Posts
    6
    Location
    did you try SendKeys after setting focus using Ctrl-End to move to the end of the text
    [vba]SendKeys "^{END}"[/vba]
    stefri

  9. #9
    Sounds like that would do it, but I keep getting the following error:
    Type mismatch: 'SendKeys'
    Any idea why?

    Thanks,
    Doug

    [VBA]
    Sub CommandButton_click()
    Set objPage = Item.GetInspector.ModifiedFormPages("Message")
    Set objControl = objPage.Controls("Message")
    objControl.SetFocus
    SendKeys "^{END}"
    End Sub
    [/VBA]

  10. #10
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,938
    Location
    Hi,

    I think you need the Application bit preceeding it. Can you use:

    [vba]Application.SendKeys "^{END}" [/vba]


    Does that help?

  11. #11
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    Are you sure you are using VBA? Some of your syntax looks more like VBScript. Is this a customization of an existing form or a form you created from scratch with VBA?
    "All that's necessary for evil to triumph is for good men to do nothing."

  12. #12
    Application.SendKeys does not work.

    I would guess it is a customization of an existing form.

    I started this process through the Outlook menus Tools > Forms > Design a Form...
    and chose the message form to begin with. So does that mean all my script is VBScript?

    Would I be better off doing this another way and what tools would I need to do that.

    Thanks,
    -Doug

  13. #13
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    Yeah you're using VBScript instead of VBA, which is why some of the code isn't working as expected. That's not to say you can't do what you want, but we need to find out if someone can help with the VBScript - that's not my strong point.

    Any VBScripters here?
    "All that's necessary for evil to triumph is for good men to do nothing."

  14. #14
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    Oh - as for another method. You could use VBA if you can't get VBScript to do what you need. The tradeoff is with deployment. Designing the form the way you are now makes it easy to publish it to your users. If you choose the VBA route, you'll lose any centralized management of the form, and will have to dance around the end-user installation.

    To use VBA, press ALT-F11 to bring up the VBA Editor. Unlike other Office apps that store code in an individual document, all OL VBA code is stored in one project called VBAProject.OTM. To insert a form, Just select Insert | UserForm. Same thing for modules.

    For centralized, more complex Outlook forms, folks generally use VB6 or VS .Net to create an Add-in.

    Cheers,
    James
    "All that's necessary for evil to triumph is for good men to do nothing."

  15. #15
    VBAX Regular
    Joined
    May 2004
    Location
    Paris, France
    Posts
    6
    Location
    Application can be found in the Item object
    Try Item.Application.SendKeys
    If we are lucky....
    stefri

  16. #16
    No luck.

    Nice try though!

  17. #17
    VBAX Regular
    Joined
    May 2004
    Location
    Paris, France
    Posts
    6
    Location
    I wonder if this is even possible....
    Quite disappointed about item.application.sendkeys
    stefri

  18. #18
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    While re-reading this thread, I wondered whether or not you ever tried adding the line

    [vba]
    objControl.SelStart = objControl.TextLength + chr(13)
    [/vba]

    before the

    [vba]
    objControl.SetFocus
    [/vba]

    If not, give that a try and let us know what happens.

    Cheers,
    James
    "All that's necessary for evil to triumph is for good men to do nothing."

  19. #19
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    Hi Doug,
    Were you ever able to get this to work?

    Cheers,
    James
    "All that's necessary for evil to triumph is for good men to do nothing."

Posting Permissions

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