ApplyBulletDefault未应用于Do-Loop

时间:2017-08-25 09:17:47

标签: excel excel-vba vba

我正在Excel中工作并填写一个单词模板(以前从未这样做过) 首先,我在列中搜索特定条目,然后创建一个填充具有行特定值的项目符号。这是代码:

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  

所以不存在任何关于不存在的值的问题(我希望)

1 个答案:

答案 0 :(得分: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