< návrat zpět

MS Excel


Téma: odoslat Mail rss

Zaslal/a 21.6.2010 15:27

nio313Ahoj Mam udelane makro na odosielanie mailu bohuzial sa my nejak nedary pridat prilohu klidne by stacil aktualnzy sheet a automaticky odoslat bez toho aby som to musem odkliknut (send):

Dik za kazdy nazor 2

Sub Blue_mail()

Set Outlook_Aplication = CreateObject("Outlook.Application")
Set Outlook_Aplication_MAPI = Outlook_Aplication.GetNamespace("MAPI")
Set Outlook_Aplication_ITEM = Outlook_Aplication.CreateItem(0)

Outlook_Aplication_ITEM.Importance = olImportanceHigho

Outlook_Aplication_ITEM.Display
'olMail.Display

Const olFormatHTML As Integer = 2
Const olMail As Integer = 43
Dim oOL As Object, oInsp As Object

Dim SourceTO As String
Dim SourceCC As String
Dim SourceSU As String
Dim SourceBody As String

SourceTO = Sheets("Blue").Range("A1")
SourceCC = Sheets("Blue").Range("A2")
SourceSU = Sheets("Blue").Range("A3")
SourceBody = Sheets("Blue").Range("A4")

Set oOL = CreateObject("Outlook.Application")
instance
Set oInsp = oOL.ActiveInspector

oInsp.CurrentItem.BodyFormat = olFormatHTML

Outlook_Aplication_ITEM.To = SourceTO
Outlook_Aplication_ITEM.CC = SourceCC
Outlook_Aplication_ITEM.Subject = SourceSU
Outlook_Aplication_ITEM.Body = SourceBody

'Outlook_Aplication_ITEM.Send
End Sub

Zaslat odpověď >

#001850
nio313
Tak som to dokumal :tady pro vse co maji podobny problem a tiez zacinaju s VBA

Set Destwb = ActiveWorkbook

'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2010
'We exit the sub when your answer is NO in the security dialog that you only
'see when you copy a sheet from a xlsm file with macro's disabled.
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With

' 'Change all cells in the worksheets to values if you want
' For Each sh In Destwb.Worksheets
' sh.Select
' With sh.UsedRange
' .Cells.Copy
' .Cells.PasteSpecial xlPasteValues
' .Cells(1).Select
' End With
' Application.CutCopyMode = False
' Destwb.Worksheets(1).Select
' Next sh

'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Part of " & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.to = "ron@debruin.nl"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add Destwb.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Send
End With
On Error GoTo 0
.Close savechanges:=False
End With

'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
4citovat

Uživatelské menu

Nejste přihlášen(a)
avatar\n

Menu

Formulář Faktura

Formulář Faktura IV

Oblíbený formulář Faktura byl vylepšen a rozšířen.
Více se dočtete zde.

Helios iNuvio

Používáte podnikový systém Helios iNuvio? Potřebujete pomoci se správou nebo vyvinout SQL proceduru? Více informací naleznete na stránce Helios iNuvio.

On-line nástroje