Boa Tarde Família,
Estou tentando executar esse cod para abrir o outlook e deixa-lo aberto em uma determinada hora porem nao estou conseguindo, fazer ele abrir o outlook
Preciso que o outlook seja aberto para quando chega um Email Aciona uma regra que ja criei essa regra aciona uma macro pra baixa o arquivo que chega no e-mail e para que isso aconteça tenho que abrir o outlook so abrir e deixa-lo aberto agradeço pela atenção
Cod Pra abrir o Outlook - Nao consigo faze-lo abrir o outlook
Sub ChamarRotinaParaAbrirOutlook()
'Este exemplo executa AbreOutlook às 07:00:00
Application.OnTime TimeValue("07:00:00"), "AbreOutlook"
End Sub
Sub AbreOutlook()
Dim Olook As Outlook.Application
Set Olook = CreateObject("Outlook.Application")
Dim ns As Outlook.Namespace
Dim Folder As Outlook.MAPIFolder
Set ns = Olook.GetNamespace("MAPI")
Set Folder = ns.GetDefaultFolder(olFolderInbox)
Olook.Explorers.Add Folder
'faz o que tem que fazer
Olook.Quit
Set Olook = Nothing
End Sub
Cod que baixa o arquivo do email Funcionando
Sub Limite(Item As MailItem)
Dim OutlookOpened As Boolean
Dim outApp As Outlook.Application
Dim outNs As Outlook.NameSpace
Dim outFolder As Outlook.MAPIFolder
Dim outAttachment As Outlook.Attachment
Dim outItem As Object
Dim outMailItem As Outlook.MailItem
Dim inputDate As String, subjectFilter As String
Dim saveInFolder As String
SendKeys ("{ENTER}")
saveInFolder = "C:2017"
If Right(saveInFolder, 1) <> "" Then saveInFolder = saveInFolder & ""
subjectFilter = "limite"
SendKeys ("{ENTER}")
OutlookOpened = False
On Error Resume Next
Set outApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Set outApp = New Outlook.Application
OutlookOpened = True
End If
On Error GoTo 0
If outApp Is Nothing Then
MsgBox "Cannot start Outlook.", vbExclamation
Exit Sub
End If
Set outNs = outApp.GetNamespace("MAPI")
SendKeys ("{ENTER}")
'Set outFolder = outNs.Folders("Personal Folders").Folders("Inbox") 'CHANGE FOLDER AS NEEDED
Set outFolder = outNs.PickFolder 'OR USER SELECTS FOLDER
If Not outFolder Is Nothing Then
For Each outItem In outFolder.Items
If outItem.Class = Outlook.OlObjectClass.olMail Then
Set outMailItem = outItem
If outMailItem.Subject = subjectFilter Then
Debug.Print outMailItem.Subject
For Each outAttachment In outMailItem.Attachments
outAttachment.SaveAsFile saveInFolder & outAttachment.FileName
Next
End If
End If
Next
End If
If OutlookOpened Then outApp.Quit
Set outApp = Nothing
End Sub
Postado : 30/08/2017 9:49 am