Written by Allen Wyatt (last updated December 8, 2021)
This tip applies to Word 2007, 2010, 2013, and 2016
Charles created a macro to insert lorem ipsum text in a document. He turned on the macro recorder, typed =lorem(), and then pressed Enter. This, of course, inserted the loreem ipsum text. He placed a shortcut to the macro on the Quick Access Toolbar, but the recorded macro only partially works. It types =lorem() for him, but he still needs to manually press Enter. Charles has tried to edit the macro to have it include the Enter command so that when he clicks on the macro shortcut the text gets entered, but to no avail.
If you want your macro to simulate pressing Enter, then you'll need to use the SendKeys command. Chances are good that when you recorded your macro, it looks very similar to this:
Sub Macro1() ' ' Macro1 Macro ' ' Selection.TypeText Text:="=lorem()" Selection.TypeParagraph End Sub
What you need to do is to replace the last line of the macro (the one just before End Sub) to either of the following:
SendKeys "~", True SendKeys "{ENTER}", False
Either of these lines (you only need one of them) will simulate pressing Enter. There is one gotcha to be aware of, however—SendKeys works in whatever window is currently active. This means you cannot run the macro from within the Visual Basic Editor and get the desired effect. The reason is because when you do that, it is the window in the Editor that is active, so SendKeys "presses Enter" within that window. You should only run the macro when your Word document window is active.
That being said, there is another way you could approach the macro, without using the SendKeys command. All you need to do is to create a new Word document that contains your lorem ipsum text, followed by whatever you want. Name this something unique, such as LoremText.docx. Then, create a macro like this one:
Sub Lorem() Selection.InsertFile FileName:="C:\Users\User\Desktop\LoremText.docx" End Sub
You just need to make sure that the path and filename shown in the macro represents the actual path and filename appropriate for your system. When you run the macro, Word goes out and grabs the LoremText.docx document and inserts it at the insertion point.
Finally, there is another way you could approach this issue without the need of resorting to macros. You could, if desired, insert the lorem ipsum text into your document, select it, and save it as a Building Block or as an AutoCorrect entry. You can then easily insert the text—modified in whatever way you desire—using these Word tools. (How to create and use both Building Blocks and AutoCorrect entries has been covered in other WordTips.)
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13484) applies to Microsoft Word 2007, 2010, 2013, and 2016.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!
Cross-referencing has long been a capability in Word documents. You can easily add and remove cross-references but ...
Discover MoreAntonyms are words that have opposite meanings. The grammar tools available in Word can suggest antonyms for some words. ...
Discover MoreSome people, while developing documents, like to use the Highlighter tool quite a bit. It can quickly get monotonous, ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2016-10-25 07:48:41
Ken Endacott
Steve. Many organisations control options in the copy of Word loaded onto workstations so that Macro Settings is not available.
Jenifer. You will win the bet every time because =rand(), =lorem() and =rand.old() generate text that has settings to inhibit spell checking. Try copying part (not whole paragraphs) of the Latin text to elsewhere in the document and spelling errors will be shown. That is unless you have a Latin dictionary loaded.
2016-10-24 10:49:34
Amy
Could you skip the whole =rand or =lorem process by adding a "word" to your custom dictionary that swaps in the (lorem) text you want? That would avoid the need to mouse to the icon, and avoid the macro security.
2016-10-24 09:28:31
Steve
Paul, I agree with Allen... restricting the use of macros all together only reduces productivity. It is true that people can create harmful macros and can be saved to a document when passed to others via email, etc., but you may have some options. First, its possible that your company simply disables macros by default, which means that you may be able to simple alter the settings for your local copy of Word. Try going to File, then Options, Trust Center, Trust Center Settings, Macro Settings. See how its currently set and if there is a suitable option for you, such as "Disable all macros with notification", or "Disable all macros except digitally signed macros".
2016-10-24 09:11:55
Jennifer Thomas
Use =rand(x,y) for English or =lorem(x,y) for pseudo-Latin.
I particularly like adding the y value of '1' for demonstrating formatting options on sample title or list paragraphs, but that works better with lorem than with rand.
Just a thought for those pondering how to use this tool (other than to win a bet that you can create 5 pages of correctly-spelled text in less than a minute, which earned me 20 reluctantly-given bucks one time - geek-fun at its finest!).
2016-10-24 08:46:08
allen@sharonparq.com
Paul: That's pretty strict! Using macros is what can make any Office application *MUCH* more productive for individual office needs. Prohibiting them actually hobbles what employees can do for the company.
-Allen
2016-10-24 06:16:38
Paul Franklin Stregevsky
Art,
Everywhere I've worked for the past 15 years, MS Office macros have been prohibited.
2016-10-23 15:09:24
Art Osgatharp
Paul -
Create a macro as described in the article, then add an icon for the macro to your Quick Access toolbar (More Commands...Choose commands from: Macros. Select your macro and click Add).
2016-10-23 06:30:43
Paul Franklin Stregevsky
I can't find a command or shortcut for this feature that I can hang on my Quick Access Toolbar. Anyone?
2016-10-22 21:38:57
Geof Richardson
Hi
More on =rand(x)
=rand(x,y)
x= number of paragraphs
y = number sentences per paragraph
Regards
Geof
2016-10-22 18:41:38
Art Osgatharp
Another way to insert random text is the rand command: =rand(number of paragraphs desired). Typing =rand(10) and pressing Enter will insert 10 paragraphs of readable random text. This can be used in a macro in the same way as the =lorem command.
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments