/ /更新マクロを開き、バックグラウンドでOutlookの配布リストを保存する - Excel、VBA、Excel-VBA、Outlook

バックグラウンドでOutlook配布リストを開いて保存するマクロを更新する - Excel、Excel、Excel、Outlook

私はExcelの連絡先をOutlook配布リスト。私は与えられたコードでそれを行うことができました。 Excelシートが閉じられるたびにマクロを実行しました。これは明示的にOutlookを開き、毎回[保存して閉じる]を選択する必要があります。以下は私のコードです:

Public Sub DistributionList()

Dim objOutlook As New Outlook.Application
Dim objNameSpace As Outlook.Namespace
Dim objDistList As Outlook.DistListItem
Dim objMail As Outlook.MailItem
Dim objRecipients As Outlook.Recipients


Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objDistList = objOutlook.CreateItem(olDistributionListItem)
Set objMail = objOutlook.CreateItem(olMailItem)
Set objRecipients = objMail.Recipients
objDistList.DLName = "Green"

Dim ws As Worksheet
Set ws = Sheets("Sheet1")

Dim lRow As Long
lRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
ws.Range("$A$1:$C" & lRow).AutoFilter Field:=3, Criteria1:="1"

Dim rRng As Range, cel As Range
Set rRng = ws.Range("B2:B" & lRow).SpecialCells(xlCellTypeVisible)


For Each cel In rRng
objRecipients.Add cel
Next

objDistList.AddMembers objRecipients
objDistList.Display
objRecipients.ResolveAll

Set objOutlook = Nothing
Set objNameSpace = Nothing
Set objDistList = Nothing
Set objMail = Nothing
Set objRecipients = Nothing

ws.AutoFilterMode = False

End Sub

マクロの保存と閉じるを避けるためにマクロにコードを含める方法があるかどうかを知りたい。

配布リストがバックグラウンドで開き、それ自体を保存するようにコードを修正する方法はありますか?

回答:

回答№1は0

削除する objDistList.Display 追加:

objDistList.Save
objDistList.Close

これはあなたの目的を達成するはずです。よろしく、