作者:枫涵笑 | 来源:互联网 | 2023-05-19 01:02
UpdateIhavecreatedanarraytoloopthroughsomerowstograbdata.Ithenwanttoinsertthisin
Update
I have created an array to loop through some rows to grab data. I then want to insert this into the table I have already created in the outlook template.
更新我创建了一个数组来遍历一些行以获取数据。然后我想将它插入到我已在outlook模板中创建的表中。
VBA Code
Sub employeeArray()
Dim managerEmployees() As Variant
Dim r As Long, c As Long
Dim objWord
Dim objDoc
Dim objRange
Dim objTable
useractivity.Activate
r = sheet1.ListObjects("Table1").ListRows.Count
c = 8
ReDim managerEmployees(1 To r, 1 To c)
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add
Set objRange = objDoc.Range
Set objTable = objDoc.Tables.Add(objRange, r, c)
For r = LBound(managerEmployees, 1) To UBound(managerEmployees, 1)
For c = LBound(managerEmployees, 2) To UBound(managerEmployees, 2)
managerEmployees(r, c) = Range("A2").Offset(r, c).Value
Next c
Next r
For r = LBound(managerEmployees, 1) To UBound(managerEmployees, 1)
For c = LBound(managerEmployees, 2) To UBound(managerEmployees, 2)
objTable.Cell(r, c).Range.Text = managerEmployees(r, c)
Next c
Next r
Erase managerEmployees
End Sub
EXAMPLE - Outlook Template
示例 - Outlook模板
EXAMPLE - Excel worksheet named sheet1 and table named Table1
示例 - 名为sheet1的Excel工作表和名为Table1的表
Currently I am trying to open the table in word (only because I don't know how to do it in outlook, yet)
目前我正试图用词打开表(只是因为我不知道如何在Outlook中做到这一点)
The Array is holding the data from the table and then creating a table in Word to paste the data in. This is now working although I now need to get this in Outlook rather than word
数组正在保存表中的数据,然后在Word中创建一个表来粘贴数据。这现在正在工作,虽然我现在需要在Outlook而不是单词中得到它
Does anyone have any suggestions?
有没有人有什么建议?
2 个解决方案