Dialog called up multiple times when saving emails from macro

Status
Not open for further replies.

Izbi

New Member
Outlook version
Outlook 2007
Email Account
This macro saves selected emails into a folder chosen by function "BrowseForFolder". If I select "n" emails to save, the dialog comes up "n" times. Is there a way to call it up just once?

Code:
Option Explicit

Public Sub Save_Messages_Select_Ask2()

Dim oMail As Outlook.MailItem
Dim objItem As Object
Dim sPath As String
Dim dtDate As Date
Dim sName As String
Dim enviro As String

enviro = CStr(Environ("USERPROFILE"))
For Each objItem In ActiveExplorer.Selection

If objItem.MessageClass = "IPM.Note" Then
Set oMail = objItem

sName = oMail.Subject

dtDate = oMail.ReceivedTime
sName = Format(dtDate, "yyyy mm dd", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, " hhnn", _
vbUseSystemDayOfWeek, vbUseSystem) & " - " & sName & ".msg"

sPath = BrowseForFolder(enviro & "\Documents\")
Debug.Print sPath & "\" & sName
oMail.SaveAs sPath & "\" & sName, olMSG

End If
Next

End Sub

Function BrowseForFolder(Optional OpenAt As Variant) As Variant

Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please choose a folder", 0, OpenAt)

On Error Resume Next
BrowseForFolder = ShellApp.self.Path
On Error GoTo 0

Set ShellApp = Nothing
Select Case Mid(BrowseForFolder, 2, 1)
Case Is = ":"
If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
Case Is = "\"
If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
Case Else
GoTo Invalid
End Select

Exit Function

Invalid:
BrowseForFolder = False

End Function
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
it's inside the loop -
For Each objItem In ActiveExplorer.Selection
next

move it above the loop.


Code:
sPath = BrowseForFolder(enviro & "\Documents\")


For Each objItem In ActiveExplorer.Selection

If objItem.MessageClass = "IPM.Note" Then
Set oMail = objItem

sName = oMail.Subject

dtDate = oMail.ReceivedTime
sName = Format(dtDate, "yyyy mm dd", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, " hhnn", _
vbUseSystemDayOfWeek, vbUseSystem) & " - " & sName & ".msg"


Debug.Print sPath & "\" & sName
oMail.SaveAs sPath & "\" & sName, olMSG

End If
Next

ETA: oops - can't move everything above the loop, just the folder picker.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
D.Moore PickFolder dialog "extension" Outlook VBA and Custom Forms 0
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
P IMAP Folders Dialog Box Using Outlook 1
P Suppress dialog box on email check error? Using Outlook 5
S Reminder Dialog Open Button Using Outlook 2
Laurent Duchastel New email setup dialog doesn't allow alias Using Outlook 2
Diane Poremsky Enter Network Password Dialog Keeps Popping Up New Slipstick.com Articles 0
Diane Poremsky Rules & Alerts Dialog Won't Open New Slipstick.com Articles 1
moron save as & file location dialog box popup Outlook VBA and Custom Forms 2
N Outlook dialog about retention policy Using Outlook 3
P VBA for Dialog Box when sending Email Using Outlook 8
R Need code to gather value of custom field on addressentry.details dialog box Using Outlook 3
D Contacts as default in Select Names dialog Using Outlook 1
B Sign-in dialog pops up repeatedly for shared calendars Using Outlook 1
H Attachment dialog box "Always do this action" greyed out Using Outlook 4
N Receive "Requested Operation Failed" Dialog when trying to add BCM Database in Outlook 2010 Using Outlook 2
R how do I eliminate allow access dialog box using VBAproject in Out Outlook VBA and Custom Forms 1
J Select Names Dialog Box Outlook VBA and Custom Forms 16
P Open Advanced Search Dialog Outlook VBA and Custom Forms 1
A outlook AdvanceFind dialog Outlook VBA and Custom Forms 5
S how to add my custom items to "Change E-mail Account" dialog Outlook VBA and Custom Forms 1
J Save As dialog box on screen Outlook VBA and Custom Forms 1
H How turn off outlook security warning dialog box from outlook Outlook VBA and Custom Forms 1
R (Outlook2003)Monitor change for "to" "cc" "bcc" on message compose dialog? Outlook VBA and Custom Forms 6
P How to Open File Selector dialog in VBA Outlook VBA and Custom Forms 4
B Browse Dialog Box Outlook VBA and Custom Forms 1
M Outlook2007 and VSTO, handle the Click on the Save Button in the IPM.Note dialog HOWTO? Outlook VBA and Custom Forms 4
J common dialog Outlook VBA and Custom Forms 1
B how/what dialog boxes can I display from VBA code Outlook VBA and Custom Forms 1
A Can't add a column called "name" to Inbox? Using Outlook 1
P Aborting ItemChange if ItemRemove Event Handler will be called nex Outlook VBA and Custom Forms 1
S What's the appointment ribbon called? Outlook VBA and Custom Forms 1
E After resizing Custom Task Pane "BeforeFolderSwitch" Event handler stopps being called Outlook VBA and Custom Forms 11
E After resizing Custom Task Pane "BeforeFolderSwitch" Event handler stopps being called Outlook VBA and Custom Forms 11
K OnButtonClick event in MSOutlook called twice. Outlook VBA and Custom Forms 2
J Multiple calendars Using Outlook 0
C Multiple emails Using Outlook 3
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
E Asking user to select multiple options in a list in an email Outlook VBA and Custom Forms 0
A Multiple signatures Using Outlook 2
O Outlook tasks - Add text column with multiple lines Using Outlook 3
R How to get the Items object of the default mailbox of a specific account in a multiple account Outlook? Outlook VBA and Custom Forms 0
I Saving attachments from multiple emails and updating file name Outlook VBA and Custom Forms 0
L Multiple Inboxes Using Outlook 3
RBLampert Accessing Outlook accounts from multiple computers Using Outlook 8
Martull Forced signature when multiple accounts exist Outlook VBA and Custom Forms 4
T Outlook 2010 Correct way to map multiple contact fields Using Outlook 4
Y Open and Save Hyperlink Files in multiple emails Outlook VBA and Custom Forms 9
O Multiple email accounts - hesitate to create a new profile Using Outlook 3
papa.deblanc Multiple Instances Using Outlook 6

Similar threads

Top