Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2017, 03:10 AM
dejanm83 dejanm83 is offline Word macro - remove shading from active para. and assign language to it, keep text cursor position Windows 10 Word macro - remove shading from active para. and assign language to it, keep text cursor position Office 2013
Novice
Word macro - remove shading from active para. and assign language to it, keep text cursor position
 
Join Date: Mar 2017
Posts: 2
dejanm83 is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 03-19-2017, 05:03 AM
macropod's Avatar
macropod macropod is offline Word macro - remove shading from active para. and assign language to it, keep text cursor position Windows 7 64bit Word macro - remove shading from active para. and assign language to it, keep text cursor position Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 03-19-2017, 07:46 AM
dejanm83 dejanm83 is offline Word macro - remove shading from active para. and assign language to it, keep text cursor position Windows 10 Word macro - remove shading from active para. and assign language to it, keep text cursor position Office 2013
Novice
Word macro - remove shading from active para. and assign language to it, keep text cursor position
 
Join Date: Mar 2017
Posts: 2
dejanm83 is on a distinguished road
Thumbs up

Thanks a bunch, that does the trick!
So I guess the key is in
.Paragraphs.First.Range
Reply With Quote
  #4  
Old 03-19-2017, 02:36 PM
macropod's Avatar
macropod macropod is offline Word macro - remove shading from active para. and assign language to it, keep text cursor position Windows 7 64bit Word macro - remove shading from active para. and assign language to it, keep text cursor position Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by dejanm83 View Post
So I guess the key is in
.Paragraphs.First.Range
Yes, otherwise, all you're working with is the actual selection.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



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
Word macro - remove shading from active para. and assign language to it, keep text cursor position 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
Word macro - remove shading from active para. and assign language to it, keep text cursor position 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

Other Forums: Access Forums

All times are GMT -7. The time now is 07:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft