我有一段代码在outlook中运行。代码贯穿电子邮件正文并将特定单词复制到Excel单元格中。
代码在Office 2010中运行得很好,但是当我在Office 2013中使用代码时,单词会将额外的字符串复制到excel单元格。
Private Sub deffolder_Click()
Unload Me
Dim olapp As Outlook.Application
Dim oAccount As Outlook.Account
Dim fqdn() As String, host() As String, server() As String, y As Long
Dim si() As String, ar() As String, ur() As String, emoc As String
Dim xlapp As Object ' Excel.Application
Dim xlwkb As Object ' Excel.Workbook
Dim folder As Outlook.MAPIFolder, ns As Outlook.NameSpace, tempfol
Dim item As Object
ReDim Preserve ar(n)
ReDim Preserve ur(n)
Dim trigger As String
n = 0
X = 0
Set ns = GetNamespace("MAPI")
For Each oAccount In Application.Session.Accounts
If oAccount = "example@email.com" Then
Set folder = oAccount.DeliveryStore.GetDefaultFolder(olFolderInbox)
start:
If folder.Items.Count > 0 Then
MsgBox "Copying Servers from emails..", vbInformation, "Info"
Set xlapp = CreateObject("Excel.Application") ' New Excel.Application
Set xlwkb = xlapp.Workbooks.Add
For Each item In folder.Items
'Set Sender = item.Sender
If item.Subject Like "test" And item.Sender Like "Tested*" Then
fqdn() = Split(Replace(item.body, "VM IP", "VM Name: "), "VM Name: ")
fqdn(1) = Replace(fqdn(1), vbNewLine, vbNullString)
X = X + 1
'Writing Values in Excel Sheet for Servers from Cloud Emails
xlapp.Cells(X, "A") = fqdn(1)
xlapp.Cells.wraptext = False
End If
End if
End if
Next
excel中的单元格值包含“预期输出”和“*”以及“tabspace”。有什么建议/想法吗?
通过使用fqdn(1)= Replace(fqdn(1),“*”,vbNullString),我可以替换“astriex”但无法使用相同的方法替换“制表符空间”。首先,在“办公室2013”引起问题,我想知道!
答案 0 :(得分:0)
您是否有机会查看Outlook邮件的HTML标记?有什么不同吗?
无论如何,您使用Split函数删除其他空格(如果有)。或者只使用Word对象模型。
Outlook对象模型提供了三种使用项主体的主要方法:
您可以在Chapter 17: Working with Item Bodies中详细了解所有这些方式。我们取决于你选择处理消息体的方式。