If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > program button to prompt for input which opens webaddress of your choice

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-09-11, 22:08
ranjah ranjah is offline
Registered User
 
Join Date: Jul 2005
Posts: 137
Red face 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
Reply With Quote
  #2 (permalink)  
Old 03-10-11, 14:54
lijon lijon is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 03-16-11, 12:11
ranjah ranjah is offline
Registered User
 
Join Date: Jul 2005
Posts: 137
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
File Type: zip button.zip (7.6 KB, 3 views)
Reply With Quote
  #4 (permalink)  
Old 03-16-11, 13:22
lijon lijon is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 03-16-11, 13:45
ranjah ranjah is offline
Registered User
 
Join Date: Jul 2005
Posts: 137
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
Reply With Quote
  #6 (permalink)  
Old 03-17-11, 13:31
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On