Results 1 to 20 of 20

Thread: [RESOLVED] Split Firstname Lastname to Hyperlink

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Split Firstname Lastname to Hyperlink

    vb Code:
    1. myarr = split(textbox1)
    2. lastname = myarr(1)
    3. 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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    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:
    http://edirectory.mycompany.com/ldap...ndEmployee&sn=lastname&givenname=firstname&MiddleInitial=&telephoneNumber=
    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.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    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.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    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.

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Split Firstname Lastname to Hyperlink

    Alright, it is erroring on: myarr = Split(TextBox1) variable not defined.

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    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.

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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:
    1. Dim myArr() As String
    2. Dim FirstName As String
    3. Dim LastName As String
    4. myArr = Split(TextBox1, "&")
    5. Lastname = myArr(1)
    6. Firstname = myArr(0)
    7. 'this is only here to see what we are getting
    8. 'once you are happy with the result, take this
    9. 'line of code out
    10. Msgbox myArr(0) & " " & myArr(1)

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    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&)

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    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. ;-)

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    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..

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Split Firstname Lastname to Hyperlink

    That did it.. It works! You guys are the Bomb!

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: [RESOLVED] Split Firstname Lastname to Hyperlink

    Can you guys help me out on another problem?
    http://www.vbforums.com/showthread.php?t=590919

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
  •  



Click Here to Expand Forum to Full Width