0
我想將Excel中的聯繫人導出到Outlook通訊組列表中。我能夠用給定的代碼做到這一點。每次關閉Excel表格時,我都會讓宏運行。這明確地打開了Outlook,我們必須每次選擇保存並關閉。下面是我的代碼:更新宏以在後臺打開並保存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
我想知道是否有什麼辦法可以包括在宏觀避免保存並關閉窗口開放代碼。
有沒有一種方法可以修改代碼,以便通訊組列表在後臺打開並自行保存?
請參閱[鏈接](http://stackoverflow.com/questions/14634453/how-to-use-workbook-saveas-with-automatic-overwrite/14634781#14634781) – Sorceri