2017-08-25 12 views
0

私はExcelで作業しており、単語テンプレートを入力しています。
まず、特定のエントリの列を検索してから行固有の値を持つ箇条書きを作成します。ここにコードがあります:Do-LoopにApplyBulletDefaultが適用されていません

With wd.Selection 
    .GoTo what:=wdGoToBookmark, Name:="launches" 

    'Loop until cycled through all unique finds 
    Do Until foundCells Is Nothing 

    .Range.ListFormat.ApplyBulletDefault '<----- this doesn't work 

    'Find next cell with value 
    Set foundCells = Sh.Columns(2).FindNext(After:=foundCells) 
    Name = foundCells.Offset(0, 3).Value & Chr(11) 
    action = foundCells.Offset(0, 5).Value & Chr(11) 
    .TypeText (Name & " " & action) 

    'Test to see if cycled through to first found cell 
     If foundCells.Address = FirstFound Then Exit Do 
Loop 
End With 

私が見つけたすべてのセルに対して箇条書きを作成したいと思います。強調表示された行は、Doループ内にある場合は機能しませんが、ループ外では機能します...問題はどこですか?

編集: 上記に入る前に、私は存在しない値のため、以下のチェックをやってる:

Set foundCells = Sh.Columns(2).Find(what:=month) 
'Test to see if anything was found 
If Not foundCells Is Nothing Then 
    FirstFound = foundCells.Address 
Else 
    GoTo NothingFound 
End If 

ので、非既存の値に関するすべての問題があるはずの(私は願っています)

+0

(opt1)の後、または(opt2)「foundCells Is Nothing」までの間に、「msgBox(foundCells Is Nothing)」という行を付けることはできますか? opt1:メッセージボックスをポップアップしないと、foundCells変数は何もありません。 opt2:messageBoxは "true"または "false"を表示します。もしそれが真実なら、見つかったセルは何もない、もし偽であればループに入り、私たちはあなたの問題を見つけ続けるだろう...;) – Kathara

+0

答えのための@Kathara Thx - 私はこれをカバーしていると思う...編集を参照してください – dv3

+0

ok foundCellsはどのように定義しましたか?範囲として?セルとして? – Kathara

答えて

1

これを試しても動作するか教えてもらえますか?

With wd.Selection 
    .GoTo what:=wdGoToBookmark, Name:="launches" 

    .Range.ListFormat.ApplyBulletDefault '<----- this doesn't work  

    'Loop until cycled through all unique finds 
    Do Until foundCells Is Nothing 

    'Find next cell with value 
    Set foundCells = Sh.Columns(2).FindNext(After:=foundCells) 
    Name = foundCells.Offset(0, 3).Value & Chr(11) 
    action = foundCells.Offset(0, 5).Value & Chr(11) 
    .TypeText (Name & " " & action & vbNewLine) 

    'Test to see if cycled through to first found cell 
     If foundCells.Address = FirstFound Then Exit Do 
Loop 

End With 
+0

これは実際には動作します.... vbNewLine to the rescue - Thx! – dv3

+0

私は助けることができてうれしいです;) – Kathara

関連する問題