|
-
Nov 7th, 2009, 12:33 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Split Firstname Lastname to Hyperlink
I have a Userform with a Textbox. I need to Split the Firstname Lastname into a Hyperlink.
Here is the code I have from another Textbox to Hyperlink:
Code:
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 Sub CommandButton1_Click()
Dim lngOpenPage As Long
lngOpenPage = ShellExecute
'This is from a past project
(Application.hwnd, "Open", "http://eic.mycompany.com/eic_drw/qr/" & TextBox1.Text, 0&, 0&, 0&) 'What are the 0& at the end of this?
'lngOpenPage = ShellExecute
'This is the one I need to execute. I just need the Firstname Lastname split from Textbox1.
(Application.hwnd, "Open", "http://edirectory.mycompany.com/ldap/CorpDirServlet?snMatch=exact&givennameMatch=exact&action=FindEmployee&sn=Lastname&givenname=Firstname&MiddleInitial=&telephoneNumber=
End Sub
-
Nov 7th, 2009, 05:35 AM
#2
Re: Split Firstname Lastname to Hyperlink
vb Code:
myarr = split(textbox1) lastname = myarr(1) firstname = myarr(0)
assumes names separated by single space
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 7th, 2009, 06:40 PM
#3
Thread Starter
Hyperactive Member
Re: Split Firstname Lastname to Hyperlink
I can't seem to get the link right. Here's what I have.
This is the Original Link:
Code:
Private Sub CommandButton1_Click()
myarr = Split(TextBox1)
lastname = myarr(1)
firstname = myarr(0)
Dim lngOpenPage As Long
lngOpenPage = ShellExecute(Application.hwnd, "Open", "http://edirectory.mycompany.com/ldap/CorpDirServlet?snMatch=exact&givennameMatch=exact&action=FindEmployee&sn=" & lastname, &"givenname=" & firstname, &"MiddleInitial=&telephoneNumber=", 0&, 0&, 0&)
'disregard just here for reference.
'lngOpenPage = ShellExecute(Application.hwnd, "Open", "http://eic.vzbi.com/eic_drw/qr/" & TextBox1.Text, 0&, 0&, 0&)
End Sub
Last edited by tome10; Nov 7th, 2009 at 06:45 PM.
-
Nov 7th, 2009, 07:50 PM
#4
Re: Split Firstname Lastname to Hyperlink
middle initial is not taken into account here, if required
are you sure application.hwnd is valid in your excel, it is not in excel 2000
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 7th, 2009, 10:24 PM
#5
Thread Starter
Hyperactive Member
Re: Split Firstname Lastname to Hyperlink
I have Excel 2003. I really don't know what Application.hwnd is. I know the other link that is there for reference works. The Middle initial is not needed. I know if I enter a firstname and lastname in the right position in the link it works.
-
Nov 7th, 2009, 11:42 PM
#6
Re: Split Firstname Lastname to Hyperlink
msgbox application.hwnd
will show if it is valid
or type application.h
see if hwnd is in the list
otherwise replace with 0
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 8th, 2009, 03:08 PM
#7
Re: Split Firstname Lastname to Hyperlink
take out the commas after lastname and firstname.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 8th, 2009, 06:03 PM
#8
Thread Starter
Hyperactive Member
Re: Split Firstname Lastname to Hyperlink
I did the Application. and hwnd did show up in the list. Is hwnd used to verify the link is valid prior to executing?
Here's what I have with error comments:
Code:
Private Sub CommandButton1_Click()
myarr = Split(TextBox1)
lastname = myarr(1)
firstname = myarr(0)
Dim lngOpenPage As Long
lngOpenPage = ShellExecute(Application.Hwnd, "Open", "http://edirectory.mycompany.com/ldap/CorpDirServlet?snMatch=exact&givennameMatch=exact&action=FindEmployee&sn=lastname&givenname=firstname&MiddleInitial=&telephoneNumber= 'Errors. Compile Error: Expected: list seperator or ). And interestingly the ' I put at the beginning to write this comment didn't work and vba thinks this comment is part of the link.
'lngOpenPage = ShellExecute(Application.hwnd, "Open", "http://start.mycompany.com/people/Results.aspx?q=" & firstname & lastname, 0&, 0&, 0&) 'When I try this it Errors on MyArray Variable not Defined
'Example works
'lngOpenPage = ShellExecute(Application.hwnd, "Open", "http://start.mycompany.com/people/Results.aspx?q=" & TextBox1.Text, 0&, 0&, 0&)
End Sub
Last edited by tome10; Nov 8th, 2009 at 06:13 PM.
-
Nov 9th, 2009, 09:05 PM
#9
Re: Split Firstname Lastname to Hyperlink
you did not close the quotes on the link
try like
Code:
"http://edirectory.mycompany.com/ldap/CorpDirServlet?snMatch=exact&givennameMatch=exact&action=FindEmployee&sn=" & lastname & "&givenname=" & firstname & "&MiddleInitial=&telephoneNumber="
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 9th, 2009, 09:31 PM
#10
Thread Starter
Hyperactive Member
Re: Split Firstname Lastname to Hyperlink
Alright, it is erroring on: myarr = Split(TextBox1) variable not defined.
-
Nov 10th, 2009, 02:57 AM
#11
Re: Split Firstname Lastname to Hyperlink
Alright, it is erroring on: myarr = Split(TextBox1) variable not defined.
so define it
dim myarr() as string
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 10th, 2009, 11:33 AM
#12
Thread Starter
Hyperactive Member
Re: Split Firstname Lastname to Hyperlink
ok, I defined it, and now it errors on Lastname not defined. So I tried to Dim Lastname as string.. That didn't work. So I tried Set. It errored saying I can't Set an array..
Code:
Dim myarr() As String
myarr = Split(TextBox1)
lastname = myarr(1)
firstname = myarr(0)
Last edited by tome10; Nov 10th, 2009 at 11:40 AM.
-
Nov 10th, 2009, 11:42 AM
#13
Re: Split Firstname Lastname to Hyperlink
myarr = Split(TextBox1) - I see that you want to split the contents of textbox1, but what character are you doing the split on? (Where is the space in this: lastname&givenname=firstname)Try:
vb Code:
Dim myArr() As String
Dim FirstName As String
Dim LastName As String
myArr = Split(TextBox1, "&")
Lastname = myArr(1)
Firstname = myArr(0)
'this is only here to see what we are getting
'once you are happy with the result, take this
'line of code out
Msgbox myArr(0) & " " & myArr(1)
-
Nov 10th, 2009, 01:10 PM
#14
Thread Starter
Hyperactive Member
Re: Split Firstname Lastname to Hyperlink
The array is working now thanks Hack.. But my link is still not working.
Compile Error: Argument not Optional.
Code:
Dim lngOpenPage As Long
lngOpenPage = ShellExecute(Application.hwnd, "Open", "http://edirectory.mycompany.com/ldap/CorpDirServlet?snMatch=exact&givennameMatch=exact&action=FindEmployee&sn=" & LastName & "&givenname=" & FirstName & "&MiddleInitial=&telephoneNumber=")
This works:
Code:
lngOpenPage = ShellExecute(Application.hwnd, "Open", "http://start.mycompany.com/people/Results.aspx?q=" & FirstName & " " & LastName, 0&, 0&, 0&)
-
Nov 10th, 2009, 01:14 PM
#15
Re: Split Firstname Lastname to Hyperlink
That is because you are missing parameters on the first one.
Look at the ShellExecute declaration.
Count the number of parameters it is looking for, and then take a look at your code and see how many you are actually passing to it.
-
Nov 10th, 2009, 05:32 PM
#16
Thread Starter
Hyperactive Member
Re: Split Firstname Lastname to Hyperlink
Hack, Syntax Error I do not Comprehend..
I think I know your talking about this:
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
And I think your talking about the break points "," / sections in this link.
Code:
Dim lngOpenPage As Long
lngOpenPage = ShellExecute(Application.hwnd, "Open", "http://edirectory.mycompany.com/ldap/CorpDirServlet?snMatch=exact&givennameMatch=exact&action=FindEmployee&sn=" & LastName & "&givenname=" & FirstName & "&MiddleInitial=&telephoneNumber=")
but it makes no sense to me. Can you explain? Sorry I can't afford a real school so you guys are all I have. ;-)
-
Nov 11th, 2009, 02:11 AM
#17
Re: Split Firstname Lastname to Hyperlink
you need to fill the other parameters
ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long
first one is hwnd, 2nd is operation (open) 3rd is file (or shortcut)
the ones you are omitting
4th is parameters, 5th is working directory, 6th is widow type to display (showcmd)
in your previous post the one that works, has 0 for each of the last 3 parameters
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 11th, 2009, 03:05 PM
#18
Thread Starter
Hyperactive Member
Re: Split Firstname Lastname to Hyperlink
Man, the original post where I received that code, I asked what those 0's were for but I never got an answer.. I'll try that..
-
Nov 11th, 2009, 03:12 PM
#19
Thread Starter
Hyperactive Member
Re: Split Firstname Lastname to Hyperlink
That did it.. It works! You guys are the Bomb!
-
Nov 11th, 2009, 09:22 PM
#20
Thread Starter
Hyperactive Member
Re: [RESOLVED] Split Firstname Lastname to Hyperlink
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|