![]() |
|
#1
|
|||
|
|||
![]()
In Word, whilst there is an open document there is always a selection, as the cursor must always be somewhere in the document.
If you select something in code and don't want that to be selected when your code has finished, you must move the selection somewhere else. A common way to do this is to record what was selected at the start and re-select it at the end. For example: Code:
Dim initSel As Range: Set initSel = Selection.Range 'working code initSel.Select For the specific case in your question it is not necessary to select the entire row. To prevent errors, your code should first check that the selection is inside a table. Then you can access the row and its cells from the selection, as below. Code:
Sub TblCellShadeOf_TEN_Percent() If Selection.Information(wdWithInTable) Then With Selection.Rows(1).Cells With .Shading .Texture = wdTextureNone .ForegroundPatternColor = wdColorAutomatic .BackgroundPatternColor = wdColorGray10 End With End With End If End Sub |
#2
|
|||
|
|||
![]() Quote:
And thank you for the lesson! We VBA-seemingly-forever-newbs get far recording our actions, but don't always know how to fix things so the code is nice and neat and efficient! ![]() Thank you! |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need to apply Heading1 to select rows | bobk544 | Word VBA | 3 | 06-09-2018 05:24 AM |
VBA Word Table - Select More than 1 Column at a time - Apply Formatting | jc491 | Word VBA | 12 | 09-24-2015 06:03 AM |
![]() |
Jennifer Murphy | Word VBA | 9 | 01-29-2012 06:50 PM |
![]() |
KIM SOLIS | Excel | 2 | 11-04-2011 06:09 PM |
![]() |
Styler001 | Word | 4 | 01-25-2010 06:40 PM |