Does anyone know what the code is to insert a hyperlink? Oviously you can go to to Insert > Hyperlink. I currently have a macro to create an automatic email based on certain criteria.
Is there anyway to do this based on a line or two of code?
Does anyone know what the code is to insert a hyperlink? Oviously you can go to to Insert > Hyperlink. I currently have a macro to create an automatic email based on certain criteria.
Is there anyway to do this based on a line or two of code?
Re: Inserting Hyperlink
There's numerous examples here or there's a workbook example in the VBA section at http://www.excel-it.com
Re: Inserting Hyperlink
Alright, let me back up. I need this for Outlook, not Excel. Sorry if I left out any information.
Re: Inserting Hyperlink
Try this previous thread
http://www.ozgrid.com/forum/showthre…email+hyperlink
Re: Inserting Hyperlink
Alright,I thank you for getting back to me. I did some testing with no such luck.
Below is what I came up with trying to understand how the hyperlink code works.
Any suggestions?
Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
Private Sub CommandButton1_Click()
If ComboBox1.Value = "Test Name" Then
Dim olApp_1 As Outlook.Application
Dim objMail_1 As Outlook.MailItem
Dim SigString1 As String
Dim Signature1 As String
Set olApp_1 = Outlook.Application
'Create e-mail item
Set objMail_1 = olApp_1.CreateItem(olMailItem)
Set myRecipientTO1_1 = objMail_1.Recipients.Add("Test Name")
SigString1 = "C:\Documents and Settings\Microsoft\Signatures\Name.htm"
If Dir(SigString1) <> "" Then
Signature1 = GetBoiler(SigString1)
Else
Signature1 = ""
End If
Unload UserForm2
With objMail_1
.Subject = TextBox1.Value + " " + TextBox3.Value + " Some Kind Of Test For Me"
.BodyFormat = olFormatPlain
.HTMLBody = "<HTML><BODY>This is a test" & "<file:\\Test Server\Loo Here\>"
.Display
End With
Else
MsgBox "Please select a NAME."
End If
End Sub
Display More
Re: Inserting Hyperlink
Where exactly are you trying to hyperlink to? Can you post the address.
In your code example there are references to Textbox controls. Do you have such controls?
Re: Inserting Hyperlink
The hyperlink is to a networked folder. Thus when I send out the email, the recipient will click on the link thus opening up a new window so they can browse the files located within that folder.
Yes the textboxs work along with all other controls.
Re: Inserting Hyperlink
This simple test worked for me.
I have replaced server and folder name with generic text
[vba]Sub Test()
'
' Include reference to Outlook library
'
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Dim myRecipientTo As Outlook.Recipient
Set olApp = Outlook.Application
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
Set myRecipientTo = objMail.Recipients.Add("Test Name")
With objMail
.Subject = " Some Kind Of Test For Me"
.Body = "This is a test <file:\\ServerName\FolderName>"
.Display
End With
End Sub[/vba]
Re: Inserting Hyperlink
No such luck.
Here's what I currently have.
Private Sub CommandButton1_Click()
If ComboBox1.Value = "NAME" Then
Dim olApp_1 As Outlook.Application
Dim objMail_1 As Outlook.MailItem
Dim SigString1 As String
Dim Signature1 As String
Set olApp_1 = Outlook.Application
'Create e-mail item
Set objMail_1 = olApp_1.CreateItem(olMailItem)
Set myRecipientTO1_1 = objMail_1.Recipients.Add("NAME")
SigString1 = "C:\Documents and Settings\NAME.warminster\Application Data\Microsoft\Signatures\NAME.htm"
If Dir(SigString1) <> "" Then
Signature1 = GetBoiler(SigString1)
Else
Signature1 = ""
End If
Unload UserForm2
With objMail_1
.Subject = TextBox1.Value + " " + TextBox3.Value + " PDF Signoffs & Dumps"
.BodyFormat = olFormatPlain
' .HTMLBody = "<HTML><BODY>Betty – " & "<br>" & "File are now available on the server " + TextBox4.Value & "<br><br>" & Signature1
.HTMLBody = "<HTML><BODY><file:\\SERVER\Imaging\Softproof\>" & Signature1
.Display
End With
Else
MsgBox "Please select a CSR."
End If
End Sub
Display More
The reason I have the .HTMLBody is because I'm pulling in Signature1.
I've also tried the following:
Private Sub CommandButton1_Click()
If ComboBox1.Value = "NAME" Then
Dim olApp_1 As Outlook.Application
Dim objMail_1 As Outlook.MailItem
Dim SigString1 As String
Dim Signature1 As String
Set olApp_1 = Outlook.Application
'Create e-mail item
Set objMail_1 = olApp_1.CreateItem(olMailItem)
Set myRecipientTO1_1 = objMail_1.Recipients.Add("NAME")
SigString1 = "C:\Documents and Settings\NAME.warminster\Application Data\Microsoft\Signatures\NAME.htm"
If Dir(SigString1) <> "" Then
Signature1 = GetBoiler(SigString1)
Else
Signature1 = ""
End If
Unload UserForm2
With objMail_1
.Subject = TextBox1.Value + " " + TextBox3.Value + " PDF Signoffs & Dumps"
.BodyFormat = olFormatPlain
' .HTMLBody = "<HTML><BODY>Betty – " & "<br>" & "File are now available on the server " + TextBox4.Value & "<br><br>" & Signature1
.Body = "<file:\\SERVER\Imaging\Softproof\>"
.Display
End With
Else
MsgBox "Please select a CSR."
End If
End Sub
Display More
This result produces "<file:\\SERVER\Imaging\Softproof\>" in the body of my email without a hyperlink.
Not quite sure what's up with this..... :confused:
Re: Inserting Hyperlink
It definetely has something to do with the .HTMLBody I am using. I just tried using .Body without the Signature1 and it worked. I went back and added Signature1 and it produced alot of junk, junk I wouldn't get if I was using .HTMLBody
Suggestions are always appreciated.
Re: Inserting Hyperlink
For html use this
[vba]
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY><A href=""File://SERVER/Imaging/Softproof/"">Betty</A> – " & "<br>" & "File are now available on the server " & TextBox4.Value & "<br><br>" & Signature1
[/vba]
Re: Inserting Hyperlink
Sorry I haven't got back to you sooner, but I came up with some code very similar to the one you posted. All works well and thanks for the assistance. :cool:
Don’t have an account yet? Register yourself now and be a part of our community!