2016-10-05 3 views
1

Word 문서에서 단어를 뒤집고 싶습니다. "elpmaS texT"는 "Sample Text"가됩니다.단어 단위로 단어를 역순으로 바꾸십시오.

For Each word In ActiveDocument.Words 
    word = StrReverse(word) 
Next word 

가 작동하지 않습니다하지만 :

나는 이런 식으로 뭔가를 시도했다.

어떻게하면됩니까? 각 루프를 사용하는 경우

답변

3

, 당신은 단어를 변경할 수 없습니다, 그래서 for 루프를 사용

Dim i As Integer 

For i = 1 To ActiveDocument.Words.Count Step 1 

    ActiveDocument.Words(i) = StrReverse(ActiveDocument.Words(i)) & " " 
Next i 
+0

감사합니다. 선택한 텍스트에 대해 어떻게합니까? – amitairos

0
Sub ReverseSelectedWords() 
    Dim i As Integer 
    Dim oWords As Words 
    Dim oWord As Range 

    Set oWords = Selection.Range.Words 

    For i = 1 To oWords.Count Step 1 

     Set oWord = oWords(i) 

     ''Make sure the word range doesn't include a space 
     Do While oWord.Characters.Last.text = " " 
      Call oWord.MoveEnd(WdUnits.wdCharacter, -1) 
     Loop 

     Debug.Print "'" & oWord.text & "'" 
     oWord.text = StrReverse(oWord.text) 

    Next i 

End Sub