[英]Word VBA: Macro to change cells in selection, and create a summary table of the tables?
[英]Preserving table selection in Word 2003 VBA macro
我的目标是为Word 2003编写一个VBA宏,用户在其中选择表的一部分(尤其是列),并且该宏将输入字符映射到特定的输出字符,例如aeiou变为V ; 有些序列像呃变成V ; 删除一个字符(感叹号); 任何没有变成“ V”的东西都会变成“ C”。 我的问题是,在第一次替换之后,所选内容将“未设置”,因此更改会影响除原始所选内容以外的其他内容。
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWildcards = True
.Replacement.Text = "V"
.Text = "[aeiouáéíóú]"
.Execute Replace:=wdReplaceAll
'replace certain sequences
.Text = "[mn" & ChrW(618) & ChrW(650) & "]" & ChrW(769)
.Execute Replace:=wdReplaceAll
.Text = "[mn]" & ChrW(768)
.Execute Replace:=wdReplaceAll
'delete !
.Text = "[\!]"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
'everything else becomes C
.Text = "[!V]"
.Replacement.Text = "C"
.Execute Replace:=wdReplaceAll
End With
如何获得查找/替换以仅对选定的单元格进行操作? 我注意到,在第一次替换之后,Selection.End更改为与Selection.Start相同的值。 我不了解Word中的列选择如何工作。
我创建了一些宏来简化此操作。 这将开始有关如何在列之间移动的答案。
Sub GoToTop()
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument ' This takes the pointer to the body of the document ' place cursor the body of the document in case you are located on the header
Selection.EndKey Unit:=wdStory 'key ctrl end
Selection.HomeKey Unit:=wdStory 'key ctrl end
End Sub
Sub GoToColumnTable() 'place cursor inside of the first column
Selection.GoTo What:=wdGoToTable
End Sub
Sub ColumnMove() 'move from one column to the other one
Selection.Move Unit:=wdColumn, Count:=1
End Sub
Sub ColumnSelect() 'select the entire column in which the cursor is
Selection.SelectColumn
End Sub
Sub ColumnDelete() 'delete a column that was selected
Selection.Columns.Delete
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.