更新
我创建了一个数组来遍历一些行来获取数据。然后我想将它插入到我已在outlook模板中创建的表中。
VBA代码
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
示例 - Outlook模板
示例 - 名为sheet1的Excel工作表和名为Table1的表
目前我正试着用语言打开表格(只是因为我不知道如何在Outlook中做到这一点)
数组正在保存表中的数据,然后在Word中创建一个表来粘贴数据。这现在正在工作,虽然我现在需要在Outlook中而不是单词
有人有任何建议吗?
答案 0 :(得分:0)
完成工作的最简单方法是使用Word对象模型来修改邮件正文。
Outlook对象模型提供了三种使用项主体的方法:
您可以在MSDN中的Chapter 17: Working with Item Bodies中详细了解所有这些方法。
例如:
k'
答案 1 :(得分:0)
请务必转到Tools > References > Microsoft Excel 14.0
图书馆对象(14.0是您的Excel版本。我的是2010年)。
完成后,您可以按以下步骤操作:
Sub GetInfo()
'Define an Excel object
Dim ExcelApp As New Excel.Application
'Define objects
Dim WB As Workbook
Dim WS As Worksheet
Dim r As Object
Dim L As Long
'Visible = false meaning Excel will be running invisible
ExcelApp.Visible = False
Set WB = ExcelApp.Workbooks.Open("Path to Excel file")
Set WS = WB.Worksheets(1) '1 is the first sheet
L = WS.Cells(WS.Rows.Count, 1).End(-4162).Row 'finding the lastrow of data considering (1 means column A of your table. If A (1) is not in your table, change it to whatever letter)
Set r = WS.Range("A1:C" & L) 'Adjust it to the columns of your data
Dim Table As Variant 'Table is 1-based
Table = r.Value
'Quit Excel
WB.Close
ExcelApp.Quit
'Outlook goes go here
End Sub