在开始编写代码之前,先添加对Outlook 8.0 object library的引用。代码如下:Option ExplicitDim App As Object Dim Itm As ObjectSet App = CreateObject("Outlook.Application") Set Itm = App.CreateItem(0) With Itm .Subject = "A tip from vbCode Magician" .To = "[email protected]" .Body = "认住新VB,真材实料有保证" .Send End With
利用ShellExecute()来做到内定Brower/Mail 的呼叫,而ShellExecute的用法请查 如何直接开启一个文件'需2个 Label 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 Const SW_SHOW = 5 Const SW_SHOWMAXIMIZED = 3 Const SW_SHOWNOACTIVATE = 4Private Sub Form_Load() Label1.Caption = "VB心得笔记" Label1.ForeColor = vbRed Label2.Caption = "与我联络" Label2.ForeColor = vbRed End Sub Private Sub Label1_Click() Call ShellExecute(Me.hWnd, "open", "http://sunh.hosp.ncku.edu.tw/~cww/", "", "", SW_SHOWMAXIMIZED) End SubPrivate Sub Label2_Click() Call ShellExecute(Me.hWnd, "open", "mailto:[email protected]", "", "", SW_SHOW) End Sub'但有一个更快的方式,便是使用Shell指令来呼叫 start.exe 'eg. Shell "Start mailto:[email protected]" 'eg. Shell "Start http://http://sunh.hosp.ncku.edu.tw/~cww"
在VB中用Outlook发电子邮件
在开始编写代码之前,先添加对Outlook 8.0 object library的引用。代码如下:Option ExplicitDim App As Object
Dim Itm As ObjectSet App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
.Subject = "A tip from vbCode Magician"
.To = "[email protected]"
.Body =
"认住新VB,真材实料有保证" .Send
End With
如何直接开启一个文件'需2个 Label
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
Const SW_SHOW = 5
Const SW_SHOWMAXIMIZED = 3
Const SW_SHOWNOACTIVATE = 4Private Sub Form_Load()
Label1.Caption = "VB心得笔记"
Label1.ForeColor = vbRed
Label2.Caption = "与我联络"
Label2.ForeColor = vbRed
End Sub
Private Sub Label1_Click()
Call ShellExecute(Me.hWnd, "open", "http://sunh.hosp.ncku.edu.tw/~cww/", "", "", SW_SHOWMAXIMIZED)
End SubPrivate Sub Label2_Click()
Call ShellExecute(Me.hWnd, "open", "mailto:[email protected]", "", "", SW_SHOW)
End Sub'但有一个更快的方式,便是使用Shell指令来呼叫 start.exe
'eg. Shell "Start mailto:[email protected]"
'eg. Shell "Start http://http://sunh.hosp.ncku.edu.tw/~cww"