gpt4 book ai didi

vba - 没有 .Display 的电子邮件正文为空

转载 作者:行者123 更新时间:2023-12-05 07:31:46 27 4
gpt4 key购买 nike

我读过这个:VBA Outlook 2010 received mail .Body is empty但它是旧的,当我点击它时找不到答案中引用的其他问题。

这是我的基本代码。

Sub AutoReplyTrap(objInMail As MailItem)

Dim objOutMail As Outlook.MailItem

Dim vText As Variant
Dim sText As String
Dim strID As String
Dim sSubject As String
Dim vItem As Variant
Dim vFirstName As Variant
Dim i As Long
Dim j As Integer
Dim strSignature As String
Dim strSigString As String
Dim strFirstName As String
Dim strFirstLetter As String
Dim strEMailAddress As String
Dim blnFirstName As Boolean
Dim blnEMail As Boolean

' change the bodyformat to plain text
objInMail.BodyFormat = Outlook.OlBodyFormat.olFormatPlain

objInMail.Display

blnFirstName = False
blnEMail = False
j = 0

' believe there is a timing issue that Body may not be fully loaded.
' so I'm going to pause and loop through 20 times to see if it gets loaded.
WaitForBody:
sText = objInMail.Body
If sText = "" Then
If j < 20 Then
j = j + 1
Sleep 1000
GoTo WaitForBody
End If
End If

If sText = "" Then
MsgBox ("No body in email!")
Exit Sub
End If

End Sub

我认为这是一个时间问题,所以我建立了循环来测试我是否有 body ,如​​果没有,等一下再试最多20次。

我有 objInMail.Display 它可以工作,但如果我删除该行,它将循环执行 20 次尝试。

如果我可以“取消显示”它,我可以忍受显示,但我想知道 .close 是否会关闭电子邮件中的所有内容,我会再次丢失正文。

我希望它在没有 objInMail.Display 的情况下工作。

最佳答案

忽略原因,这可能会提供一个没有 .Display 的解决方法。

Option Explicit

Private Sub test_GetInspector()

Dim currSel As Object
Set currSel = ActiveExplorer.Selection(1)

If currSel.Class = olMail Then
AutoReplyTrap_GetInspector currSel
End If

End Sub

Sub AutoReplyTrap_GetInspector(objInMail As mailItem)

' change the bodyformat to plain text
objInMail.BodyFormat = OlBodyFormat.olFormatPlain

' objInMail.GetInspector ' Previously "valid".
' My setup finally caught up and provided the clue.
' Directly replacing .Display with .GetInspector
' Compile error:
' Invalid use of property

' https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem.getinspector
Dim objInspector As Inspector
Set objInspector = objInMail.GetInspector

' You should find this is necessary
'objInMail.Save

End Sub

关于vba - 没有 .Display 的电子邮件正文为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51639665/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com