I am creating a macro using VBA with Excel, that accesses Outlook 365, loops trough e-mails and saves them as files.
So far it’s working fine, the problem is when files are being saved, windows pops up a window showing the progress of copying each file, like so:
Salvando como means saving as in portuguese
This is detrimental because there are gonna be hundreds of e-mails being saved, so it’s gonna take a while for it to end. During this time I need users to be able to do other things without affecting the macro. Excel itself does not need to be available during this time.
The way it is now, the user can be browsing the web for example, this pop up will show in front of anything and make this window active, meaning if the user was typing something it will be stopped, and hitting enter will cancel the file saving…
Ideally, user will hit a button and see a message in a worksheet sayng macro in progress until it ends.
I have already tried:
Application.DisplayAlerts = False
and
Application.DisplayStatusBar = False
and
Dim blnStatusVisible As Boolean
With Application
blnStatusVisible = .DisplayStatusBar
.DisplayStatusBar = False
End With
'code goes here
Application.DisplayStatusBar = blnStatusVisible
but it does not work..
My code so far is this:
Sub exportEmails(ByVal caixaPostal As String, ByVal nomeCaixaPostal As String, ByVal emailCaixaPostal As String)
Dim outlookApp As outlook.Application
Dim outlookNamespace As outlook.Namespace
Dim contas As outlook.folders
Dim conta As outlook.Folder
Set outlookApp = New outlook.Application
Set outlookNamespace = outlookApp.GetNamespace("MAPI")
Set contas = outlookNamespace.folders
For Each conta In contas
'Debug.Print conta.Name
If conta.Name = "account" Then
On Error Resume Next
loopEmail conta.folders("Inbox").Items
On Error GoTo 0
End If
Next
Set outlookApp = Nothing
Set outlookNamespace = Nothing
Set contas = Nothing
Set conta = Nothing
End Sub
Sub loopEmail(ByVal emails As outlook.Items)
Dim emailLoop As Object
Dim path As String: path = \testserverfolder
For Each emailLoop In emails
If TypeOf emailLoop Is outlook.MailItem Then
Dim Email As outlook.MailItem: Set Email = emailLoop
Dim emailRemetente As String: emailRemetente = ""
'Verifica se o remetente utilizou o serviço exchange da Microsoft ou foi e-mail externo
'com SMTP, para então obter o endereço de e-mail correto
If Email.SenderEmailType = "EX" Then
emailRemetente = Email.Sender.GetExchangeUser.PrimarySmtpAddress
Else
emailRemetente = Email.SenderEmailAddress
End If
If Len(emailRemetente) = 0 Then
emailRemetente = "endEmailRemNaoEncontr"
End If
'extractLettersAndNumbers is in another module
Dim novaPasta As String: novaPasta = Left(path & extractLettersAndNumbers(emailRemetente , 194) & ""
If Len(Dir(novaPasta, vbDirectory)) = 0 Then
MkDir novaPasta
End If
'=====================================================================================
'Here is when the dialog appears!!!!!
'=====================================================================================
'Saves file ".msg"
Email.SaveAs novaPasta & "email.msg", olMSG
'Salva o arquivo ".html"
Email.SaveAs novaPasta & "email.html", olHTML
End If
Next
Set Email = Nothing
Set emailLoop = Nothing
End Sub
TL;DR I need saving as progress bar window to not be shown while running the macro
Thanks in advance!