2016-05-15 6 views
0

clear変数lastWordが必要な状況にありますので、msgboxには何も表示されません。loopクリア/エンプティ変数次のループの変数

以下のコードは単なる例です。

Sub clear_lastWord_Variable() 

    Dim wordArr() As String 
    Dim lastword As String 
    Do 
     selection.Find.ClearFormatting 
     selection.Find.Font.Bold = True 
     With selection.Find 
      .Forward = True 
      .Wrap = wdFindStop 
     End With 
     selection.Find.Execute 

     If selection.Find.Found Then 

      wordArr = Split(selection, " ") 

      For i = LBound(wordArr) To UBound(wordArr) Step 1 
       lastword = wordArr(i) 

      Next i 

      MsgBox lastword 

      ' here should be something to clear lastword 
     Else 
      Exit Do 
     End If 
    Loop 

End Sub 

答えて

5

オブジェクト以外の変数をクリアすることはできません。定義した値にしか設定できません。文字列変数の場合、通常は空の文字列""です。オブジェクト変数について

lastword = "" 

又は(同一)

lastword = vbNullString 

Set myObj = Nothingがあります。