End or change type of selection in Macro

V

Victoria

Admission: I'm horrible at code so the code below is probably VERY UGLY.

Task attempting: Have macro select TABLE and perform some tasks, then
select only the 1st COLUMN and perform additional tasks.

Problem: I can't seem to figure out how to clear the TABLE selection and
then select only column 1.

Code:
'Start TABLE selection and perform tasks

With Selection
.Sort ExcludeHeader:=False, FieldNumber:="Column 1", _
SortFieldType:=wdSortFieldAlphanumeric,
SortOrder:=wdSortOrderAscending, _
FieldNumber2:="Column 1", SortFieldType2:=wdSortFieldNumeric,
SortOrder2 _
:=wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending,
Separator:= _
wdSortSeparateByDefaultTableSeparator, SortColumn:=False,
CaseSensitive:= _
False, LanguageID:=wdEnglishUS, SubFieldNumber:="Word 1",
SubFieldNumber2 _
:="Word 2", SubFieldNumber3:="Paragraphs"
End With
Selection.Tables(1).Select
Selection.Rows.HeightRule = wdRowHeightExactly
Selection.Rows.Height = InchesToPoints(0.16)
With Selection.ParagraphFormat
.SpaceBefore = 1.8
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
.LineUnitBefore = 0
End With

'Start COLUMN selection and perform tasks
Selection.SelectColumn
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
 
H

Helmut Weber

Hi Victoria,

try:

Selection.Tables(1).Columns(1).Select

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Greg Maxey

Try something like:

Sub ScratchMacro()
Dim oTbl As Word.Table
Set oTbl = Selection.Tables(1)
With oTbl
'Do to the whole table what you are trying to do.
.Columns(1).Select
End With
With Selection.Find
.Text = " "
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
End Sub
 
H

Helmut Weber

Hi Victoria,

please give a few kisses to Greg, too,
als Greg's solution was about the same. :)

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top