如何将用户表单列表框中的选择填充到项目符号MS-Word-VBA中? [英] How To Populate Selections From A User Form List Box into Bullets MS-Word-VBA?

查看:67
本文介绍了如何将用户表单列表框中的选择填充到项目符号MS-Word-VBA中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已编辑

是指我之前问过的一个问题

Referring to a question I asked previously Word 2013- VBA- How To Add Punctuation to Results From A User Form List Box?, how would I change the following code to populate the results in a bullet format instead of commas?

Private Sub Test()
   Dim SelectedTexts As String
   Dim index As Long
   
   For index = 0 To ListBox1.ListCount - 1
      If ListBox1.Selected(index) Then
         SelectedTexts = SelectedTexts & ListBox1.List(index) & ", "
      End If
   Next

   SelectedTexts = Mid(SelectedTexts, 1, Len(SelectedTexts) - 2) & "."
   index = InStrRev(SelectedTexts, ",")
   If index > 0 Then SelectedTexts = Left(SelectedTexts, index - 1) & " and " & Right(SelectedTexts, Len(SelectedTexts) - index - 1)

   ActiveDocument.SelectContentControlsByTitle("test").Item(1).Range.Text = SelectedTexts
End Sub

推荐答案

这是一项微不足道的任务.一个人想知道您是否甚至尝试过修改现有代码.如果对它应用合适的项目符号格式,则可以使用现有的内容控件完成全部操作.例如:

This is a trivial undertaking. One wonders whether you even tried to modify your existing code. The whole lot could be done with your existing content control if you apply a suitable bullet format to it. For example:

Private Sub Test()
   Dim SelectedTexts As String
   Dim index As Long
   
   For index = 0 To ListBox1.ListCount - 1
      If ListBox1.Selected(index) Then
         SelectedTexts = SelectedTexts & ListBox1.List(index) & ";" & vbCr
      End If
   Next

   SelectedTexts = Mid(SelectedTexts, 1, Len(SelectedTexts) - 2) & "."
   index = InStrRev(SelectedTexts, vbCr)
   If index > 0 Then SelectedTexts = Left(SelectedTexts, index - 1) & " and " & Right(SelectedTexts, Len(SelectedTexts) - index + 1)

   ActiveDocument.SelectContentControlsByTitle("test").Item(1).Range.Text = SelectedTexts
End Sub

这篇关于如何将用户表单列表框中的选择填充到项目符号MS-Word-VBA中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆