none
Command button link to a URL with text field information. RRS feed

  • Question

  • I am attempting to create a cmd button on a userform in WORD which opens an URL.  I need to capture text from a textbox that is entered on the userform and it needs to be placed within the middle of the address line of the URL.  I need help in writing the VBA code to capture the data from "txtbox1" to feed into the address line within the URL which is needed when the user clicks on the cmd button. This is for an intranet site over an internet site.  Any assistance on this would be greatly appreciated thanks for having this forum to ask for "HELP".


    Ddesigns

    Thursday, May 8, 2014 4:03 PM

Answers

  • Hi,

    According to your description, I assume you want to open an URL in IE when clicking a command button in a userform and the URL is based on an intranet link and the text of a textbox.

    In fact, I’m not sure about what’s meaning of “intranet link”. But if it is a part of the URL and it is known, we just need to use the click event of the command button and resort to Internet Explorer to open an URL. Here is a sample for your reference. You could enter “worddev” into the Textbox to test it.

    Private Sub CommandButton1_Click()
    Dim str As String
    str = txtbox1.Text
    Dim URL As String
    URL = "http://social.technet.microsoft.com/Forums/office/en-US/home?forum=" & str & "&filter=alltypes&sort=lastpostdesc"
    
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.navigate URL
    Set ie = Nothing
    End Sub
    

    By the way, for more questions about VBA rather than Word Object Model, you could also consider posting in VBA forum for more effective responses.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 9, 2014 9:26 AM
    Moderator

All replies

  • Hi, I have figured out my intranet link now I am trying to figure out the data portion.  Thanks for anyone that can take a look.

    Ddesigns

    Thursday, May 8, 2014 8:04 PM
  • Hi,

    According to your description, I assume you want to open an URL in IE when clicking a command button in a userform and the URL is based on an intranet link and the text of a textbox.

    In fact, I’m not sure about what’s meaning of “intranet link”. But if it is a part of the URL and it is known, we just need to use the click event of the command button and resort to Internet Explorer to open an URL. Here is a sample for your reference. You could enter “worddev” into the Textbox to test it.

    Private Sub CommandButton1_Click()
    Dim str As String
    str = txtbox1.Text
    Dim URL As String
    URL = "http://social.technet.microsoft.com/Forums/office/en-US/home?forum=" & str & "&filter=alltypes&sort=lastpostdesc"
    
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.navigate URL
    Set ie = Nothing
    End Sub
    

    By the way, for more questions about VBA rather than Word Object Model, you could also consider posting in VBA forum for more effective responses.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 9, 2014 9:26 AM
    Moderator
  • Luna, thank you so much for your assistance with this as it works perfectly.  I wasn't sure I could access our company's intranet site with the userform.  But as long as one is logged into the network it works great.  I truly appreicate all the help as I just do a little coding.  So thanks again.


    Ddesigns

    Friday, May 9, 2014 3:13 PM
  • Please be more specific. You mean, how to get the entry in a textbox control on a VBA UserForm?

    stringVariable = TextboxDesignation.Text


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, May 11, 2014 3:55 PM
    Moderator