Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2012
    Posts
    4

    Post problem with send keys in excel vba

    hello i have a problem in excel vba send keys

    i have two values in 2 cells in my excel sheet.
    [A1=5670 A2=0005].
    and i have a webpage with two text boxes and a button and the title of that webpage is hello world.

    now my requirement is.

    i need to create a macro to copy and paste the A1 and A2 values of excel into the the webpage textboxes and click the button.

    this is the code i am using in the visual basic.
    ------------------------------------------------------------------------

    Dim fn As String
    Dim ln As String
    fn = Range("A1").Value
    ln = Range("A2").Value

    AppActivate "hello world"
    DoEvents
    Call SendKeys(fn)
    DoEvents
    Call SendKeys("{tab}")
    DoEvents
    Call SendKeys(ln)
    DoEvents
    Call SendKeys("{enter}") 'Hit enter on the "login" button
    --------------------------------------------------------

    The code is working fine.
    but the problem is, when i click on the button on the button on the excel sheet.

    it is opening the webpage named hello world.
    but it is passing the values from excel to the webpage very differntly.
    for example:-
    there is 5670 in cell A1.
    it is taking as 55670 sometimes,56770 some times,56700 sometimes.
    please tell me what is the problem with this code.
    and kindly suggest me to how to do this..
    and please recomond how to copy and paste the values into the textboxes instead of sending values..

    THanks in advance...

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,275
    NOT a GOOD way of doing it

    here some code that should help you

    Code:
    Sub InternetExplorer()
    Dim IExp As Object
    On Error Resume Next
    Dim sPage As String
    Set IExp = CreateObject("InternetExplorer.Application")
    
    IExp.Visible = True
    IExp.Navigate "http://yourwebpageyouwantto full"
    Do
    Loop While IExp.Busy = True
    IExp.Document.Forms(0).UserName.Value = ""    '<= read note
    IExp.Document.Forms(0).Password.Value = ""     '<= read note
    Call IExp.Document.Forms(0).elements("Submit").Click
    
    Set IExp = Nothing
    End Sub
    Note: mite have to view the source code to find out the Feildname you are trying to full

    to run it copy above code to a module and click once on the Sub the press F8 and that should start the Sub going press f8 to step it.





    NOW

    if you get the above working


    we can now make it beater


    Code:
    Sub Send_data(valueA,valueB)
    Dim IExp As Object
    On Error Resume Next
    Dim sPage As String
    Set IExp = CreateObject("InternetExplorer.Application")
    
    IExp.Visible = True
    IExp.Navigate "http://yourwebpageyouwantto full"
    Do
    Loop While IExp.Busy = True
    IExp.Document.Forms(0).UserName.Value = valueA
    IExp.Document.Forms(0).Password.Value = valueB
    Call IExp.Document.Forms(0).elements("Submit").Click
    Set IExp = Nothing
    End Sub
    
    
    Dim fn As String
    Dim ln As String
    fn = Range("A1").Value
    ln = Range("A2").Value
    
    call Send_data(fn,In)
    once you happy with

    set the IExp.Visible = False

    so you don't see it the screen popup.
    Last edited by myle; 11-18-12 at 05:33. Reason: spelling
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE

  3. #3
    Join Date
    Nov 2012
    Posts
    4

    problem with send keys in excel vba

    hi
    BIg thanks for replying to my problem.

    actually my requirement is.

    the webpage is already opened.
    here i no need to specify a new url and open it.

    so i request you to kindly tell me the procedure without opening a url and tell me the procedure with the already opened website..


    thanks

    i am online at facebook
    my facebook link is http://www.facebook.com/yamuneshanumandla
    please send me the link so by that we can chat. i will show you my screen..

  4. #4
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,275
    That going to be a bit harder as u have get vb to find the object ie the web page that one I could never get vb to do I just use the above code to open it then I know what the object is
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE

  5. #5
    Join Date
    Nov 2012
    Posts
    4
    so your are saying that it is completely not possible to do as per my requirement..?

  6. #6
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,275
    I have never done it your way i have alway got the code to open the page do some thing them close it
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE

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
  •