0

単語の前後に記号を挿入するための単純なマクロがあります。

Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.TypeText Text:="a"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Color = -603914241
Selection.Font.Size = 1
Selection.MoveRight Unit:=wdWord, Count:=1
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="a"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Color = -603914241
Selection.Font.Size = 1
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=1

選択したテキストの各単語をマクロでループさせる方法はありますか?

4

1 に答える 1

0

次のようなことができます。

Dim myRangeIndex As Range
Dim myRangeStart As Range

Set myRangeStart = Selection.Range

For Each myRangeIndex In myRangeStart.Words()

   myRangeIndex.Select

   Selection.MoveLeft Unit:=wdWord, Count:=1
   Selection.TypeText Text:="a"
   Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
   Selection.Font.Color = -603914241
   Selection.Font.Size = 1
   Selection.MoveRight Unit:=wdWord, Count:=1
   Selection.MoveLeft Unit:=wdWord, Count:=1
   Selection.MoveRight Unit:=wdWord, Count:=1
   Selection.MoveLeft Unit:=wdCharacter, Count:=1
   Selection.TypeText Text:="a"
   Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
   Selection.Font.Color = -603914241
   Selection.Font.Size = 1
   Selection.MoveRight Unit:=wdCharacter, Count:=1
   Selection.MoveRight Unit:=wdWord, Count:=1

Next myRangeIndex
于 2013-08-27T17:36:47.913 に答える