[英]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.