我正在尝试自己学习 VBA,我试图获取电子邮件的正文,将其解析出来,然后仅将数组的一个元素保存到 Excel 文件中。我就是这样做的,我的问题是我似乎无法让它更新文件中已有的内容。它只是用新的电子邮件信息重写并保存它。我对你的问题是:我的代码需要什么才能继续写入我的 excel 文件而不摆脱已经存在的内容。
Sub FMK(Item As Outlook.MailItem)
Const PathName = "C:\Users\carter\Desktop\fmk.xlsx"
Dim arrLines As Variant, _
varLines As Variant, _
RowNext As Integer, _
xlApp As Excel.Application, _
ExcelWkBk As Excel.Workbook, _
excWkb As Object, _
excWks As Object, _
temp As String
arrLines = Split(Item.Body, vbCrLf)
Set xlApp = Application.CreateObject("Excel.Application")
Set excWkb = xlApp.Workbooks.Add()
Set excWks = excWkb.ActiveSheet
temp = Trim(arrLines(32))
RowNext = 1
With excWks
excWks.Cells(RowNext, 1) = temp
End With
RowNext = RowNext + 1
excWkb.SaveAs PathName
excWkb.Close
'this is just for testing purposes I will remove later
MsgBox (arrLines(32))
End Sub
感谢您的时间!