+ Reply to Thread
Results 1 to 20 of 20

Userform - Open word document/ hyperlink from populated text box

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    10

    Userform - Open word document/ hyperlink from populated text box

    Hi I was hoping to get some help
    I have been searching a lot a can't find a solution anywhere

    I have a user form that I have created that is used to populate an excel spreadsheet, search and recall the data from the spreadsheet and repopulate the text boxes.
    All the data is a personal information e.g name, DOB, contact number etc

    One of the options that I have is the persons CV this document document is usually a word document but sometimes can be a PDF file this document is stored locally on a shared hard drive.
    I currently have a function to find the document and populate the textbox with the document location.
    What I would like to do is have a button next to the text box that when clicked will open the file that is populated in the text box
    I also have another text box that has the person’s website so I would like the same function to open the webpage that is inside the textbox

    Before I was using a userform I use to just have a make the text a hyperlink and click on it to open

    Is the possible? If so how would I go about doing this?

    Thanks in advance for your help

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - Open word document/ hyperlink from populated text box

    Hello chendysworld,

    You can use the Shell command to open the file. If the path is in the text box then you could use...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-03-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform - Open word document/ hyperlink from populated text box

    Hi Leith

    Thanks for your reply
    I'm quite new to VBA and have been teaching myself with the help of this forum starting with this project I am working on
    How would I insert the Shell code into the button
    If I just insert the code given I just get a debug error
    Is there anything else that I need to use to enter to make the code work?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - Open word document/ hyperlink from populated text box

    Hello chendysworld,

    Here is an example of the button code. You will need to open the Visual Basic Editor (Alt+F11) to edit the button's code. To display the button's code, double click on the button. Change the name of the Text Box to match the one you are using.
    Please Login or Register  to view this content.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - Open word document/ hyperlink from populated text box

    Hello chendysworld,

    Here is an example of the button code. You will need to open the Visual Basic Editor (Alt+F11) to edit the button's code. To display the button's code, double click on the button. Change the name of the Text Box to match the one you are using.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-03-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform - Open word document/ hyperlink from populated text box

    Hi Leith

    Thanks again
    I'm still having trouble if I use the code given I get a debug error with this part
    Please Login or Register  to view this content.
    If i use
    Please Login or Register  to view this content.
    then I get an error with the other part

    Is there any reason for this?
    I even created a new userform and with just 1 text box and button but am still getting the same error
    Thanks

  7. #7
    Registered User
    Join Date
    07-03-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform - Open word document/ hyperlink from populated text box

    I'm still not having any luck with this error
    Is there anything you could suggest?

    Thanks for your help

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - Open word document/ hyperlink from populated text box

    Hello chendysworld ,

    It would help me to see your workbook. There must be something else causing you problems with the code.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.

  9. #9
    Registered User
    Join Date
    07-03-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform - Open word document/ hyperlink from populated text box

    I have attached a basic copy of what I am trying to do for you to look at
    It gives the exact issues that I am coming across

    Many Thanks
    Attached Files Attached Files

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - Open word document/ hyperlink from populated text box

    Hello chendysworld ,

    I had to change from using the VBA Shell to using the API (Applications Programming Interface) ShellExecute to make this work properly. The attached workbook has all the changes shown here added to it.

    The "Open" button on the UserForm calls the new macro and passes the value of TextBox1 to it.
    Please Login or Register  to view this content.

    The macro checks if the file to be opened is an Excel file. If so then it will open in the same instance of Excel and the active workbook. Otherwise, the file will be opened using the program associated with it.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    07-03-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform - Open word document/ hyperlink from populated text box

    Hi Leith,
    That is amazing works perfectly thank you so much
    For the second part of my question how would I do the similar thing (press button to open textbox value) for a website address
    This other box will only have website addresses types into it nothing else so i presume it would be a bit simpler

    Thank you for all you help on this

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - Open word document/ hyperlink from populated text box

    Hello ,chendysworld

    You can use the ShellExecute call to automatically open your default browser and go to the URL. Here is an example...
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-03-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform - Open word document/ hyperlink from populated text box

    Hi Leith

    Thanks for the quick reply
    How would I edit this to open the URL typed in a specific textbox
    At the moment if I just add the code to a button I get 'sub not defined'
    Sorry if I sound a bit stupid on this

    Many Thanks

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - Open word document/ hyperlink from populated text box

    Hello chendysworl,

    Copy the code below and paste it between the Sub and End Sub lines for your button. Change the name of the TextBox from TextBox1 to the name of the text box that holds the URL.
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    07-03-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform - Open word document/ hyperlink from populated text box

    Hello Again
    When I use the code given and I am still getting an error
    'Compile Error; Sub or function not defined'
    I have attached a mock up again

    Once again thanks for your help
    Attached Files Attached Files

  16. #16
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Userform - Open word document/ hyperlink from populated text box

    Leith, correct me if I am wrong but you need to put the following code in a standard module and write a valid URL in the textbox.

    Please Login or Register  to view this content.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  17. #17
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - Open word document/ hyperlink from populated text box

    Hello chendysworld,

    @abousetta - After opening the lateset workbook, the OP forgot to copy the macro, Yes, you are correct that it needs to made Public now instead of Private.

    As pointed out, the macro had not been copied into the new workbook. I have added the macro and changed it to Public. The attached workbook contains the corrections and is working.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    07-03-2012
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform - Open word document/ hyperlink from populated text box

    Thanks so much for your help
    Works perfectly now just changed Private to Public and everything is now working perfectly

    Thanks so much for your help both Leith & Abousetta
    Much appreciated

  19. #19
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Userform - Open word document/ hyperlink from populated text box

    Hi there,
    Maybe it's a bit late to reply to your query but I have found two ways you can open an URL within a TextBox.

    1) Create a CommandButton (by clicking it, it will open the URL within the TextBox) as following:

    Please Login or Register  to view this content.
    2) By double clicking the TextBox to open URL:

    Please Login or Register  to view this content.
    I hope this helps.
    Cheers.
    Last edited by Cutter; 08-09-2012 at 01:07 PM. Reason: Added code tags

  20. #20
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Userform - Open word document/ hyperlink from populated text box

    Answered wrong post... Deleted response...
    Last edited by abousetta; 08-09-2012 at 01:05 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1