Does anyone have some code that i could use in one of my projects that when clicked will bring up a webpage in explorer/netscape or send an email in a program like outlook?
Thanks
Tom
Printable View
Does anyone have some code that i could use in one of my projects that when clicked will bring up a webpage in explorer/netscape or send an email in a program like outlook?
Thanks
Tom
VB Code:
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 Sub Command1_Click() Dim OpenPage As Long OpenPage = ShellExecute(Form1.hwnd, "Open", "http://www.vbexplorer.com", 0&, 0&, 0&) End Sub
VB Code:
Private Sub SendMailMessage(DisplayMsg As Boolean, Receiver As String, Optional AttachmentPath) Dim objOutlook As Outlook.Application Dim objOutlookMsg As Outlook.MailItem Dim objOutlookRecip As Outlook.Recipient Dim objOutlookAttach As Outlook.Attachment Dim CallDescription As String ' Create the Outlook session. Set objOutlook = CreateObject("Outlook.Application") ' Create the message. Set objOutlookMsg = objOutlook.CreateItem(olMailItem) With objOutlookMsg ' Add the To recipient(s) to the message. Set objOutlookRecip = .Recipients.Add(Receiver) objOutlookRecip.Type = olTo ' Add the CC recipient(s) to the message. Set objOutlookRecip = .Recipients.Add("an other person") objOutlookRecip.Type = olCC ' Set the Subject, Body, and Importance of the message. .Subject = "Replace this String With your subject Or variabele" .Body = "replace this String With your subject Or variabele" .Body = .Body & vbCrLf & "In this manner you can create a body larger than 256 characters" ' Add attachments to the message. If Not IsMissing(AttachmentPath) Then Set objOutlookAttach = .Attachments.Add(AttachmentPath) End If ' Resolve each Recipient's name. For Each objOutlookRecip In .Recipients objOutlookRecip.Resolve Next ' Should we display the message before sending? If DisplayMsg Then .Display Else .Send End If End With Set objOutlook = Nothing End Sub
cheers Hack :)
If you don't need to actually send the email from your app, and since not everyone has Outlook installed (I mean configured)
Than you propably just want to open the default email program, with a specified emailadress, than use this code:
VB Code:
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 Sub Command1_Click() Dim OpenPage As Long OpenPage = ShellExecute(Form1.hwnd, "Open", "mailto:[email protected]", 0&, 0&, 0&) End Sub
And in VB.NET this would be:
VB Code:
System.Diagnostics.Process.Start("mailto:[email protected]")
Good Luck!
Hey Jop: Using just the "Open", can you specifiy the text that goes into the body of a message, and attach attachments?
No, but did I say it could?
I'm not saying your code is bad or anything, just providing an alternative... the code I posted was just as an example to show the possibilities.
No, no, no Jop - you misunderstand. I'd like to know if you can do that because if you can, that would be a very cool alternative for folks that don't have Outlook. I don't know if you can. I was wondering if you knew. :D
Hehe LOL my bad :D
I don't think you can do it that way, or wait maybe you can!! :D
I remember something doing in HTML, like mailto:[email protected] and than entering the subject...
altough I can't remember the code right now... I'll have to look it up.
Sorry for the misunderstanding! ;)
Edit:
You can specify a subject by:
mailto:[email protected]?subject=HEY!
Try this:
I know this works with Outlook, not sure about other e-mail clients though.
I would very much like to have someone NOT using Outlook to test Tom_H's code and let us know if it works. :)
i think without outlook, it just popsup loads of internet explorer windows, does anyone eles get this?