Potrebujem poradit s makrom pri odosielani celeho zosita do Outlooku. Email sa odosle ale stale dostavam chybu: Počas odosielania došlo k chybe. A niekedy mi vobec nechce zatvorit outlock musim ho manulane ukoncit cez spravcu uloh.
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim OLApp As Object, eMailAdresa As String, Ucet As String, oAccount, bOK As Boolean
eMailAdresa = test@gmail.com"
Ucet = "test@gmail.com"
If MsgBox("Chcete odoslať tento súbor na email ?" & vbNewLine & eMailAdresa, vbYesNo + vbQuestion) = vbNo Then Exit Sub
On Error Resume Next
Set OLApp = GetObject(, "Outlook.Application")
If OLApp Is Nothing Then Set OLApp = CreateObject("Outlook.Application")
On Error GoTo 0
If OLApp Is Nothing Then MsgBox "Outlook nieje možné spustiť", vbCritical: Exit Sub
For Each oAccount In OLApp.Session.Accounts
If oAccount = Ucet Then bOK = True: Exit For
Next oAccount
If Not bOK Then MsgBox "Tento účet v Outlooku neexistuje." & vbNewLine & Ucet: Exit Sub
On Error Resume Next
With OLApp.CreateItem(0)
.To = eMailAdresa
.Subject = "test"
.Body = "test"
.Attachments.Add ThisWorkbook.FullName
Set .SendUsingAccount = oAccount
.Send
.Display
End With
If Err.Number <> 0 Then MsgBox "Počas odosielania došlo k chybe.", vbCritical
On Error GoTo 0
Set OLApp = Nothing
End Sub
citovat