Hello,
A very quick question.
How do I add a hyperlink to a userform, for example via a command button?
Thanks,
Hello,
A very quick question.
How do I add a hyperlink to a userform, for example via a command button?
Thanks,
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
[vba]
ActiveWorkbook.FollowHyperlink Address:="http://example.microsoft.com", _
NewWindow:=True
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Thanks xld.
On a related note, is it possible to populate a web form automatically from VBA? For example, the web page opens using the above code and then the two fields on the web page that is opened are populated by items from the excel userforms text boxes?
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
I have come across the following thread : http://www.vbaexpress.com/forum/showthread.php?t=21429
It has the code in post #2 which i've modified to suit :
[vba]
Dim ieDoc As Object
Dim sws As SHDocVw.ShellWindows
Dim strURL As String
Dim n As Integer
'Set main URL to evaluate open IE windows
strURL = "http://www.covernotes.rsagroup.co.uk...et&ITSX-7Q8ME9"
Set sws = New SHDocVw.ShellWindows
'Cycle through all open IE windows and assign the window whose URL matches strURL
For n = 0 To sws.Count - 1
If Left(sws.Item(n).LocationURL, Len(strURL)) = strURL Then
Set ieDoc = sws.Item(n).Document
sws.Item(n).Visible = True
Exit For
End If
Next n
ieDoc.all("username").Value = Me.txtUserID.Value
ieDoc.all("password").Value = Me.txtPassword.Value
ieDoc.all("Log In").Click
[/vba]
I've added the reference to internet controls, amended the code to suite the correct URL and fields, that is assuming the 'ieDoc.all....' refers to the fields on the webpage.
The code errors 'Object variable or With block variable not set' and highlights : ieDoc.all("formfield").Value = Me.txtUserID.Value
Any suggestions?
Last edited by phendrena; 03-18-2009 at 02:00 AM.
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.
Ok, i sorted it code as follows :-
[vba]Private Sub lblFordLink_Click()
Dim ieDoc As Object
Dim sws As SHDocVw.ShellWindows
Dim strURL As String
Dim n As Integer
ActiveWorkbook.FollowHyperlink Address:="http://www.covernotes.rsagroup.co.uk...et&ITSX-7Q8ME9", NewWindow:=True
'Set main URL to evaluate open IE windows
strURL = "http://www.covernotes.rsagroup.co.uk...et&ITSX-7Q8ME9"
Set sws = New SHDocVw.ShellWindows
'Cycle through all open IE windows and assign the window whose URL matches strURL
For n = 0 To sws.Count - 1
If Left(sws.Item(n).LocationURL, Len(strURL)) = strURL Then
Set ieDoc = sws.Item(n).Document
sws.Item(n).Visible = True
Exit For
End If
Next n
ieDoc.all("username").Value = Me.txtUserID.Value
ieDoc.all("password").Value = Me.txtPassword.Value
'ieDoc.all("Log In").Click <=== ????
lblFordLink.ForeColor = RGB(50, 50, 125)
lblFordLink.Font.Bold = True
lblLRMILink.ForeColor = RGB(0, 0, 255)
lblLRMILink.Font.Bold = False
lblVCILink.ForeColor = RGB(0, 0, 255)
lblVCILink.Font.Bold = False
End Sub[/vba]
The only thing i can't work out is how to click the Log In button as it doesn't have a defined name
Any suggestions?<INPUT type=submit value="Log In">
Thanks,
Last edited by phendrena; 03-18-2009 at 02:19 AM.
Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
But thats nothing compared to the horrors that lurk beneath The Trap Door.