Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2005
    Posts
    144

    Red face Unanswered: program button to prompt for input which opens webaddress of your choice

    Hi All,

    I have a very quick question regarding button in excel spreadsheet.

    What I am trying to achieve is that I would like to click on a button which will prompt me to enter doc id, such as c12345 or any other name/number and upon entering it will execute a browser with an address that has id at the end of it.
    so... after entering id url is www.something.com/c12345
    which will then open up the document that is related to this id.

    Any help/suggestions??

    Thanks

  2. #2
    Join Date
    Mar 2008
    Posts
    8
    Try this.

    Code:
    Sub GotoMyWWW()
    
    Dim ans As String
    Dim mysite As String
    
    ans = InputBox("Doc ID?")
    
        Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .Visible = True
            
        mysite = "http://www.something.com/" & ans
    
            .Navigate mysite
            Do Until .ReadyState = 4: DoEvents: Loop
               
         End With
        
    End Sub

  3. #3
    Join Date
    Jul 2005
    Posts
    144

    Red face Code not executing

    Quote Originally Posted by lijon View Post
    Try this.

    Code:
    Sub GotoMyWWW()
    
    Dim ans As String
    Dim mysite As String
    
    ans = InputBox("Doc ID?")
    
        Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .Visible = True
            
        mysite = "http://www.something.com/" & ans
    
            .Navigate mysite
            Do Until .ReadyState = 4: DoEvents: Loop
               
         End With
        
    End Sub
    Lijon,
    Thanks for your prompt response. Please excuse my ignorance when asking dumb questions. For some odd reason when I click on this button nothing happens. I have added the code behind the button but it doesnt work.
    I am attaching my spreadsheet.

    the url that it should be going to is...
    http://something.www4.bla.com/km/nac...mr_na-c0123456
    Attached Files Attached Files

  4. #4
    Join Date
    Mar 2008
    Posts
    8
    You're missing a line in the bottom sub to actually call the gotowww sub.

    Code:
    Private Sub GotoMyWWW_Click()
    Dim ans As String
    Dim mysite As String
    
    ans = InputBox("Doc ID?")
    
        Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .Visible = True
            
        mysite = "http://www.yahoo.com/" & ans
    
            .Navigate mysite
            Do Until .ReadyState = 4: DoEvents: Loop
               
         End With
    End Sub
    
    Private Sub CommandButton1_Click()
                Call GotoMyWWW_Click   '****add this!
    End Sub
    Cheers,
    Lijon

  5. #5
    Join Date
    Jul 2005
    Posts
    144

    Wink Almost Done

    Quote Originally Posted by lijon View Post
    You're missing a line in the bottom sub to actually call the gotowww sub.

    Code:
    Private Sub GotoMyWWW_Click()
    Dim ans As String
    Dim mysite As String
    
    ans = InputBox("Doc ID?")
    
        Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .Visible = True
            
        mysite = "http://www.yahoo.com/" & ans
    
            .Navigate mysite
            Do Until .ReadyState = 4: DoEvents: Loop
               
         End With
    End Sub
    
    Private Sub CommandButton1_Click()
                Call GotoMyWWW_Click   '****add this!
    End Sub
    Cheers,
    Lijon
    Hi Lijon,
    It actually works fine without that line, when adding that line it actually gives me error and highlights line starts with DO until.
    Your code is perfect.. it was my fault for not assigning it as a macro to the button.
    One last quick question:
    if I dont type anything and click either ok or cancel it opens webpage with an error saying document not found.
    How do I handle this error? can we prevent it from openning if no input has entered or clicked cancel.

    Thanks

  6. #6
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    It is not hard the find out what happens when you cancel the InputBox, but the short answer is

    Code:
    ans = InputBox("Doc ID?")
    If ans = "" Then Exit Sub
    You might also want to add some input validation ie. correct number of alpher/numeric charactures etc. before launching IE!!?

    MTB

Posting Permissions

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