简体   繁体   English

如何在MS Word中的表格内的不同行中插入Split函数的文本

[英]How do I insert the text of the Split function into different lines inside a table in MS Word

I need help with some code. 我需要一些代码的帮助。 I built a User Form in word using Bookmarks as references to where the text in each TextBox should go, I was able to accomplish that. 我使用书签创建了一个单词形式的用户表单,作为对每个TextBox中文本应去向的引用,我能够做到这一点。 The challenge I'm having now is using the Split Function. 我现在面临的挑战是使用拆分功能。 I want to grab each word from TextBox3 and place them in a table, then I want to search each word in an excel database and retrieve the info on the cell next to it (in a Vlookup sort of way). 我想从TextBox3中抓取每个单词并将它们放在表格中,然后我想在excel数据库中搜索每个单词并在其旁边的单元格上检索信息(采用Vlookup方式)。 Each word from the TextBox3 should be in a different line. TextBox3中的每个单词都应该在不同的行中。

Here is the code: 这是代码:

    Private Sub CommandButton1_Click()
With ActiveDocument
.Bookmarks("bmCN").Range _
.InsertBefore TextBox1
.Bookmarks("bmOriJob").Range _
.InsertBefore TextBox2
.Bookmarks("bmOptJob").Range _
.InsertBefore TextBox3
.Bookmarks("bmJobD").Range _
.InsertBefore TextBox4
.Bookmarks("bmJobRes").Range _
.InsertBefore TextBox5
.Bookmarks("bmJobR").Range _
.InsertBefore TextBox6
.Bookmarks("bmBen").Range _
.InsertBefore TextBox7
.Bookmarks("bmTag").Range _
.InsertBefore TextBox8

End With
 UserForm1.Hide
    Selection.WholeStory
    Selection.Fields.Update
    Selection.Collapse Direction:=wdCollapseEnd
    End Sub

Any help would be appreciated. 任何帮助,将不胜感激。

Try something like this with array and loop: 使用array和loop尝试这样的事情:
(see some comments inside the code below) (请参见下面的代码内的一些注释)

'let's create temporary array
Dim tmpArray As Variant
    tmpArray = Split(TextBox3, " ")


Dim i As Integer
For i = 1 To UBound(tmpArray)

    'we will load values to first column in first table in yur document
    ActiveDocument.Tables(1).Cell(i, 1).Range = tmpArray(i - 1)

    'here do your stuff with excel- load what you need
    'ActiveDocument.Tables(1).Cell(i, 2).Range = something from excel
Next i

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在MS Word中编写VBA宏以在表中插入饼形图 - How do write a VBA macro in MS Word to insert a Pie Chart inside a table 如何使用 VBA 将包含内容控件的自动文本插入到 MS Word 文档中? - How do I insert auto-text containing content controls into an MS Word document using VBA? 在MS-Word中,VBA如何拆分插入分节符和段落标记的表 - In MS-Word how do you VBA split a table inserting a Section Break AND a paragraph mark 导入制表符分隔的文本文件并插入到 MS Word 中的表格中 - Import tab-delimited text file and insert to a table in MS Word 如何在Word中的光标位置插入文本? - How do I insert text at my cursor location in Word? Word 2007 - 如何将带有不一致制表符的文本转换为表格? - Word 2007 - How do I convert text with inconsistent tabbing to a table? 如何通过 MS Excel VBA 在 Word 中修改纯文本内容控件 - How do I modify Plain Text Content Control in Word via MS Excel VBA 如何在搜索特定列后使用 MS Word VBA 代码对具有特定文本的单元格进行着色? - How do I use MS Word VBA code to shade cells with specific text after seaching a a specific column? 如何使用VBA在MS Word中的表格中的特定单元格中嵌入图表 - How do I Embeded an Chart in a Specific Cell in a table in MS Word with VBA 如何在 MS Word 中使用 VBA 确定表格单元格中的段落是编号还是项目符号? - How, using VBA in MS Word, do I determine if paragraphs in table cells are numbered or bulleted?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM