Consulting

Results 1 to 5 of 5

Thread: =lorem(1,1) and =rand(1,2) in macros won't update the display

  1. #1
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    3
    Location

    =lorem(1,1) and =rand(1,2) in macros won't update the display

    Hi, I'm trying to write a VBA macro to type "=lorem(1,5) <plus Enter>" into Word so that I don't have to type in the lorem string to generate the usual lorem text. If I type it in and press Enter, it gets replaced by the desired text. If I record a macro of my actions and run the macro, nothing happens until I type a space. Then the whole paragraph shows up. Same with the '=rand(2,5)' string.

    How can I change my macro to make it update the display (or run the macro after the string has been inserted into the buffer)? Thank you

    Selection.TypeText Text:="=rand(2,2)"
    Selection.TypeText Text:=vbCr

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,447
    Location
    Try:
    Sub Demo()
    SendKeys "=rand{(}2,2{)}" & vbCr
    End Sub
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    3
    Location
    That works! Thank you so much.

    I wonder why I never thought of sending the keys; I suppose sending the final key is like the one that I type after inserting the macro. I will experiment with an insertion first and a final keystroke at the end. Thank you again for your help. Where would we all be without your expertise?

    UPDATE: Yes, doing the insertion by code (as shown in my original post) followed by a SendKeys operation works great. It's sending the trailing vbCr that gets word to expand the magic rand/lorem functions.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,447
    Location
    Quote Originally Posted by kkkwj View Post
    doing the insertion by code (as shown in my original post) followed by a SendKeys operation works great. It's sending the trailing vbCr that gets word to expand the magic rand/lorem functions.
    I don't know why you'd bother with that circumlocution when the SendKeys code I posted does the lot in a single operation...
    Cheers
    Paul Edstein
    [MS MVP - Word]

  5. #5
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    3
    Location
    I was just exploring and trying to learn more, that's all. :-) Thank you again for your help.

Tags for this Thread

Posting Permissions

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