|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Word macro - remove shading from active para. and assign language to it, keep text cursor position
Hello,
I am trying to create a macro that would do what the subject says, i.e. remove shading from the paragraph in which the text cursor is located, and assign language to that paragraph, while keeping the position of the text cursor. I tried to do this by recording my actions in a macro - I select the whole paragraph, start a new macro (name it, assign a keyboard shortcut) - click the shading icon in the toolbar and pick No Color, then invoke the language menu and select and confirm the desired language - and stop recording. The macro then looks like this: Sub EngUSNoBackground() ' ' Macro1 Macro ' ' Selection.Shading.Texture = wdTextureNone Selection.Shading.ForegroundPatternColor = wdColorAutomatic Selection.Shading.BackgroundPatternColor = wdColorAutomatic Selection.LanguageID = wdEnglishUS Selection.NoProofing = False End Sub What this does when I run it while nothing is selected, is only remove shading from the whole document, and does not assign the language. When I run it again, then it changes the language of only the word where the cursor is. I could work around this by recording two steps before anything else (Ctrl+Up, Ctrl+Shift+Down) to select the paragraph, and that does the trick, but I want to keep the position of the text cursor in the paragraph. Can anyone help me with this, what do I need to put into the macro for it to be applied to the active paragraph, without having to select the text of the paragraph first? |
#2
|
||||
|
||||
Try:
Code:
Sub EngUSNoBackground() With Selection.Paragraphs.First.Range With .Shading .Texture = wdTextureNone .ForegroundPatternColor = wdColorAutomatic .BackgroundPatternColor = wdColorAutomatic End With .LanguageID = wdEnglishUS .NoProofing = False End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks a bunch, that does the trick!
So I guess the key is in .Paragraphs.First.Range |
#4
|
||||
|
||||
Yes, otherwise, all you're working with is the actual selection.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA code to assign color to an active worksheet | jane.bugai | Excel Programming | 5 | 03-03-2017 08:39 AM |
Cursor Position; WORD 2007 Question, Please | Robert11 | Word | 3 | 11-27-2015 09:42 PM |
changing cursor position | anand | Word VBA | 2 | 06-19-2015 05:18 AM |
Get para no where txt is found, and move text to end of paragraph using Word 201 | marceepoo | Word VBA | 2 | 12-20-2012 11:42 AM |
Macro for absolute text box re-position | hobbsbaboo | PowerPoint | 0 | 03-15-2012 01:44 AM |