Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1
Private Sub SendMail(lhWnd As Long, Optional Address As String, _
Optional Subject As String, Optional Body As String, _
Optional CC As String, Optional bcc As String, Optional Attachement As String)
'*********************************************************
'******** ********
'******** bygger opp en e-post melding, og sender ********
'******** denne ved å benytte default mail system ********
'******** ********
'******** NB!! Attachement fungerer KUN med ********
'******** Outlook og outlook express ********
'******** ********
'*********************************************************
Dim strCommand As String
'bygger opp "mail-strengen"
If Len(Subject) Then strCommand = "&Subject=" & Subject
If Len(Body) Then
Body = Replace(Body, "&", "%26")
Body = Replace(Body, " ", "%20")
Body = Replace(Body, vbCrLf, "%0D%0A")
Body = Replace(Body, vbCr, "%0D")
Body = Replace(Body, vbLf, "%0A")
strCommand = strCommand & "&Body=" & Body & "%0D%0A"
End If
If Len(CC) Then strCommand = strCommand & "&CC=" & CC
If Len(bcc) Then strCommand = strCommand & "&BCC=" & bcc
If Len(Attachement) Then strCommand = strCommand & "&Attacth=" & Chr(34) & Attachement & Chr(34)
'passer på at første tegn er et ?-tegn
If Len(strCommand) Then
Mid(strCommand, 1, 1) = "?"
End If
'legger til teksten "mailto:" og hoved adresse
strCommand = "mailto:" & Address & strCommand
'Starter default mail program v.h.a shellexecute
Call ShellExecute(lhWnd, "open", strCommand, _
vbNullString, vbNullString, SW_SHOWNORMAL)
End Sub
Private Sub Command1_Click()
End Sub