gpt4 book ai didi

excel - 遍历所有 Outlook 收件箱,包括共享收件箱错误

转载 作者:行者123 更新时间:2023-12-04 20:30:23 35 4
gpt4 key购买 nike

我有代码可以搜索用户的 Outlook 并根据您在工作表单元格中输入的主题短语回复电子邮件。几天前我确实让它工作了,但现在我似乎无法让它工作(已被删除)。运行后,将持续显示代码行“Set olitems = flrd.Items”的错误消息,说“对象变量或未设置 block 变量”。我认为问题出在 End if 但无论我将其放置在何处,代码都不执行任何操作或显示相同的错误。

工作代码的唯一另一个问题(当它工作时)是它填充了不止一次。我希望它只填充一次。

Sub Display()

Dim Fldr As Outlook.Folder
Dim olfolder As Outlook.MAPIFolder
Dim olMail As Outlook.MailItem
Dim olReply As Outlook.MailItem
Dim olItems As Outlook.Items
Dim i As Integer
Dim signature As String
Dim allStores As Stores
Dim storeInbox As Folder
Dim j As Long

Set allStores = Session.Stores

For j = 1 To allStores.count
On Error Resume Next
Debug.Print i & " DisplayName - " & allStores(i).DisplayName
On Error GoTo 0

Set storeInbox = Nothing
On Error Resume Next
Set storeInbox = allStores(i).GetDefaultFolder(olFolderInbox)
On Error GoTo 0

If Not storeInbox Is Nothing Then
End if
Set olItems = Fldr.Items

olItems.Sort "[Received]", True

For i = 1 To olItems.count
signature = Environ("appdata") & "\Microsoft\Signatures\"

If Dir(signature, vbDirectory) <> vbNullString Then
signature = signature & Dir$(signature & "*.htm")
Else
signature = ""
End If

signature = CreateObject("Scripting.FileSystemObject").GetFile(signature).OpenAsTextStream(1, -2).ReadAll

Set olMail = olItems(i)

If InStr(olMail.Subject, Worksheets("Checklist Form").Range("B8")) <> 0 Then
If Not olMail.Categories = "Executed" Then
Set olReply = olMail.ReplyAll

With olReply
.HTMLBody = "<p style='font-family:calibri;font-size:14.5'>" & "Hi Everyone," & _
"<p style='font-family:calibri;font-size:14.5'>" & "Workflow ID:" & " " & _
Worksheets("Checklist Form").Range("B6") & "<p style='font-family:calibri;font-size:14.5'>" & _
Worksheets("Checklist Form").Range("B11") & "<p style='font-family:calibri;font-size:14.5'>" & _
"Regards," & "</p><br>" & signature & .HTMLBody
.Display
.Subject = "RO Finalized WF:" & Worksheets("Checklist Form").Range("B6") & " " & _
Worksheets("Checklist Form").Range("B2") & " -" & Worksheets("Fulfillment Checklist").Range("B3")
End With

Exit For
olMail.Categories = "Executed"

End If
End If

Next i
Set Fldr = StoreInbox

Next

ExitRoutine:
Set allStores = Nothing
Set storeInbox = Nothing

End Sub

最佳答案

首先,去掉 On Error Resume Next线。
其次,Fldr永远不会设置变量。您的意思是使用 storeInbox变量代替?

Sub Display()

Dim Fldr As Outlook.Folder
Dim olfolder As Outlook.MAPIFolder
Dim olMail As Outlook.MailItem
Dim olReply As Outlook.MailItem
Dim olItems As Outlook.Items
Dim i As Integer
Dim signature As String
Dim allStores As Stores
Dim storeInbox As Folder
Dim j As Long

Set allStores = Session.Stores

For j = 1 To allStores.count
On Error Resume Next
Debug.Print i & " DisplayName - " & allStores(i).DisplayName
On Error GoTo 0

Set storeInbox = Nothing
On Error Resume Next
Set storeInbox = allStores(i).GetDefaultFolder(olFolderInbox)
On Error GoTo 0

If Not storeInbox Is Nothing Then

Set olItems = Fldr.Items

olItems.Sort "[Received]", True

For i = 1 To olItems.count
signature = Environ("appdata") & "\Microsoft\Signatures\"

If Dir(signature, vbDirectory) <> vbNullString Then
signature = signature & Dir$(signature & "*.htm")
Else
signature = ""
End If

signature = CreateObject("Scripting.FileSystemObject").GetFile(signature).OpenAsTextStream(1, -2).ReadAll

Set olMail = olItems(i)

If InStr(olMail.Subject, Worksheets("Checklist Form").Range("B8")) <> 0 Then
If Not olMail.Categories = "Executed" Then
Set olReply = olMail.ReplyAll

With olReply
.HTMLBody = "<p style='font-family:calibri;font-size:14.5'>" & "Hi Everyone," & _
"<p style='font-family:calibri;font-size:14.5'>" & "Workflow ID:" & " " & _
Worksheets("Checklist Form").Range("B6") & "<p style='font-family:calibri;font-size:14.5'>" & _
Worksheets("Checklist Form").Range("B11") & "<p style='font-family:calibri;font-size:14.5'>" & _
"Regards," & "</p><br>" & signature & .HTMLBody
.Display
.Subject = "RO Finalized WF:" & Worksheets("Checklist Form").Range("B6") & " " & _
Worksheets("Checklist Form").Range("B2") & " -" & Worksheets("Fulfillment Checklist").Range("B3")
End With

Exit For
olMail.Categories = "Executed"

End If
End If

Next i

End if

Next

ExitRoutine:
Set allStores = Nothing
Set storeInbox = Nothing

End Sub

关于excel - 遍历所有 Outlook 收件箱,包括共享收件箱错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51866322/

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