MS Office Forum / Word / Programming / March 2007
An idiot needs help with a macro
|
|
Thread rating:  |
Ben Covington - 05 Mar 2007 13:39 GMT I'm writing a script. I would like to write a macro that allows me to go Center/Caps On/enter text(character name)/Return/Caps Off. This seems like a pretty simple thing to do, but I have tried using the macro editor and weirdness ensues. The cap lock won't work, or the cursor returns to center on the subsequent line, or it just bounces back to the left margin...I don't know enough about the visual basic editor to just write the commands. Can anyone help? do I have to write two macros?
Thanks in advance,
Lene Fredborg - 05 Mar 2007 14:31 GMT Below you will find a small macro that lets you type your text in an inputbox. The macro will then convert the text to uppercase and insert it after the current selection, centered and with a paragraph mark after (I am not sure what you mean by “(character name)” - are you going to insert only one letter?). Since I don’t know under which circumstances you are going to use your macro, the macro below may not be what you are looking for.
Sub InsertCenteredText_AllCaps()
Dim strText As String strText = InputBox("Enter the text you want to insert.") 'Insert text followed by paragraph mark With Selection 'Insert text in uppercase .InsertAfter UCase(strText) & vbCr 'The inserted text is now selected 'Center paragraph .ParagraphFormat.Alignment = wdAlignParagraphCenter 'Position cursor in paragraph after .Collapse (wdCollapseEnd) End With End Sub
 Signature Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word
> I'm writing a script. I would like to write a macro that allows me to go > Center/Caps On/enter text(character name)/Return/Caps Off. This seems like a [quoted text clipped - 5 lines] > > Thanks in advance, Ben Covington - 05 Mar 2007 16:24 GMT Thanks for the suggestion. I tried copying and pasting into the VB editor (please remember I am an idiot) and kept getting error messages. Here's a more detailed explanation of what I am trying to accomplish. In a theatrical manuscript, the speaking character's name is centered and in all caps, for instance, if 'George' is speaking, in the center of the page would be GEORGE and his dialogue would begin on the next line, justified left. In order to do this, I have to either mouse or keyboard the cursor to center, hit the CapLock, type 'GEORGE', return, mouse or keyboard the cursor back to left and turn off the CapLock. Optimally, it would be nice if I could work this macro so that Word would do it's little "I Remember" thing, and autofill in the character's name after I type the first three letters, but I'm not going to push it. If I can just cut down on the repetitive action, I can handle typing the characters' name...
Thanks for your help,
> Below you will find a small macro that lets you type your text in an > inputbox. The macro will then convert the text to uppercase and insert it [quoted text clipped - 30 lines] > > > > Thanks in advance, Greg Maxey - 05 Mar 2007 16:43 GMT Ben,
For you uses I think I would create a series of AutoText entries for each character name.
Center justify, type GEORGE then return, Left Justify. Select the text and trailing paragraphs (2). Press ALT+F3 Type in the AUTOTEXT name "George"
Provided your AutoComplete>AutoText option "Show AutoComplete Suggestions" is enabled, then when you type Geor (must be four unique characters) then the text will be inserted as formatted above.
Note: AutoText went to hell in a handbasket with Word2007. The AutoComplete feature is no longer available in that version.
On Mar 5, 11:24 am, Ben Covington <BenCoving...@discussions.microsoft.com> wrote:
> Thanks for the suggestion. I tried copying and pasting into the VB editor > (please remember I am an idiot) and kept getting error messages. Here's a [quoted text clipped - 55 lines] > > - Show quoted text - Graham Mayor - 06 Mar 2007 07:11 GMT Other suggestions would be to use bulleted paragraph styles http://www.gmayor.com/Text_as_bullet.htm or even simpler use autocorrect You could use #G as a trigger for George etc.
 Signature <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP
My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Ben, > [quoted text clipped - 79 lines] >> >> - Show quoted text - Lene Fredborg - 05 Mar 2007 17:06 GMT I see. Then you can forget about macros (even though I would have liked knowing which error you got ;-)). You can obtain what you want using AutoTexts - one AutoText per character name:
To create a “character name” AutoText: 1. Create a paragraph with the characters name (e.g. GEORGE), centered, all caps. 2. Now select the entire character name paragraph (incl. the paragraph mark that can be seen if you turn on formatting marks by clicking the ¶ icon in the Standard toolbar). 3. Press Alt+F3. This opens the “Create AutoText” dialog box, displaying the character name you entered. Click OK.
For each of the character names, repeat the steps above (you only need to replace the name by a new name and select the paragraph again before pressing Alt+F3 to create a new AutoText).
To insert an AutoText, start typing the desired AutoText name (i.e. in your case the character name). If the first characters of the names are unique, an AutoComplete suggestion will pop up after the first 4 letters and you only need to press Enter to insert the entire AutoText. However, it is important that the first characters of each name are unique for that name - if two names are almost identical, you may add another character as the first character in one of the AutoText names.
If you need more details about how to create and use AutoTexts, see this article: http://word.mvps.org/faqs/customization/AutoText.htm
Hope this helps.
 Signature Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word
> Thanks for the suggestion. I tried copying and pasting into the VB editor > (please remember I am an idiot) and kept getting error messages. Here's a [quoted text clipped - 46 lines] > > > > > > Thanks in advance, lwildernorva - 05 Mar 2007 19:17 GMT I'd suggest a macro, a new style, and a new toolbar. This will seem a lot of work, but bear with me--it will save you a lot of time in the long run, especially if you do a lot of this kind of writing. I use a variant of this approach in my work, and it saves me tons of time every day.
If you're not familiar with styles in Word, first a brief explanation then the macro code, then the toolbar. With styles, you can apply multiple formatting characteristics, such as uppercase and center alignment, to a paragraph. By default, Word applies the style Normal to everything you type. In the Normal template (I hate how Microsoft created confusion by naming both the default template and the default style the same), you'll find a number of built-in styles in addition to the Normal style. In addition to the built-in styles, a Word user can create unique styles.
In this case, open a blank document and create the style Script Character Name by clicking "Format/Styles and Formatting. . ." A list box opens with a number of styles that are available. There is a button for "New Style. . ." which you want to hit. In the "Properties: Name" box enter "Script Character Name" (I use this term because you'll see that Word has a built-in "CharacterName" style already). For your needs, you can set the paragraph alignment to center by clicking on the radio button located roughly in the middle of the dialog box. In the lower left corner, you will see a button for "Format" which you can click to get a number of choices, including "Font." In the middle of the dialog box that opens you will see the title "Effects" which includes a checkbox for All Caps. You can make any other changes to the font here as well. Then close the dialog boxes.
Now let's go to the macro. For the moment, let's assume you have a character named George in your script. Here's the macro code for the VBA Editor:
Sub ScriptWriterGeorge() ' ' ScriptWriterGeorge Macro ' Macro recorded March 5, 2007 ' Selection.TypeParagraph Selection.Style = ActiveDocument.Styles("Script Character Name") Selection.TypeText Text:="george" Selection.TypeParagraph Selection.Style = ActiveDocument.Styles("Normal") End Sub
Assuming that you want to return to regular spacing, font, and alignment after you run the macro, which is probably based on the Normal style, the macro inserts a new paragraph from the cursor position, changes the style to the defined Script Character Name style, types "george" (but because of the style will capitalize that word and center align it), inserts another new paragraph, and returns the style to Normal so that you may enter the dialogue.
Here's where the new toolbar comes into play and makes your life easier. Right click anywhere on your toolbars and you'll get a list box with a number of toolbar entries. Look at the bottom and you'll see an entry, "Customize." Click on that, and you'll get a dialog box with three tabs. Select "Toolbars" and then "New." You'll get another box asking for the name of the toolbar. For your purposes, "Script Writing" should do. Close the dialog box, and you should see a new, small toolbar hovering in the document window. Drag this toolbar to the existing toolbars and drop it so it anchors there.
Again, right click on the toolbars. This time, select "Customize" and "Commands." In the left list box "Categories," scroll down and select the entry "Macros." The right list box will now display a list of macros, including "ScriptWriterGeorge" (by the way, it may say something like "NewMacros.ScriptWriterGeorge" or something similar). Click and drag this macro to the Script Writer toolbar. When you release the macro, it should anchor to your toolbar. Before closing the Commands box, right click on the new toolbar button, and you should see a list of items open. The third entry is "Name," and if you position the cursor in the associated box, you can edit the name of the toolbar button. I just made mine "George."
Repeat these steps for each character in your script, creating a new macro named "ScriptWriter(Name of Character)" for each character. You should have a toolbar with names of each of the characters in your script. When you want to enter their names, just hit the toolbar button.
All this seems a bit involved, but once you've done it the first time, it takes very little time to copy the steps for each character. I just created a second macro and toolbar button for a character named Bill in less than 90 seconds by copying the original macro "ScriptWriterGeorge" and changing the name to "ScriptWriterBill" and the third line to "bill." And now, instead of having to call the macro and type the name of the character each time, you just hit the toolbar button for the character's name and your hard work pays off.
Hope this helps!
> I'm writing a script. I would like to write a macro that allows me to go > Center/Caps On/enter text(character name)/Return/Caps Off. This seems like a [quoted text clipped - 5 lines] > > Thanks in advance,
|
|
|