+ Reply to Thread
Results 1 to 10 of 10

Copy / Paste a range from Excel to a textbox in IE

  1. #1
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Copy / Paste a range from Excel to a textbox in IE

    Hello All,
    Can somebody help me with a vba code to copy and paste a range of Excel data into search box in Internet Explorer and submit?

    The element ID of the textbox is "Textarea1"

    I have attached the Excel image and textbox image
    Thanks

    N
    Attached Images Attached Images
    Last edited by Niclal; 08-28-2013 at 07:11 AM.

  2. #2
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Copy / Paste a range from Excel to a textbox in IE

    Hi,
    I have used following vba script, but the thing is, I am not getting all items as in the attached textbox.PNG, but only one item remains. Obviously, the second item in the list is replacing the first, the third is replacing the second, etc. I just need the whole list pasted.

    Sub Fill_Form()
    Dim IE As Object
    Dim mytextfield As Object
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate "http://www.example.com/"
    Do Until IE.readystate = 4
    DoEvents
    Loop
    Set mytextfield = IE.document.all.Item("Textarea1")
    mytextfield.Value = Sheets(1).Range("A1").Value
    End Sub

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    Can you post the actual URL?
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Copy / Paste a range from Excel to a textbox in IE

    Unfortunately, I can't, that's why I am using http://www.example.com/

  5. #5
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Copy / Paste a range from Excel to a textbox in IE

    I have also managed to paste the items as a comma-separated string, but I need a paragraph-separated string, one item per line.
    Maybe , you have an idea how to convert the comma-separated string and paste the results, which is also a solution.
    As I already mentioned, the URL is an intranet.
    Thanks

  6. #6
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Copy / Paste a range from Excel to a textbox in IE

    I have changed the script a bit. I am almost there. I just need to convert the comma in a linebreak, and I still need your help:

    Sub Fill_Form()
    Dim IE As Object
    Dim mytextfield As Object
    Dim arrString As Variant
    Dim i As Long

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate "http://www.example.com/"
    Do Until IE.readystate = 4
    DoEvents
    Loop

    arrString = Split(Range("A1"), ",")
    For i = 0 To UBound(arrString)
    Set mytextfield = IE.document.all.Item("Textarea1")
    mytextfield.Value = arrString(i)
    Next i

    End Sub

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Copy / Paste a range from Excel to a textbox in IE

    Sorry I can't really give proper help without seeing the actual page.

    From what I see in your code all you are doing is putting the value(s) from A1 into the textbox one at a time, not all together.

    Also, the code doesn't seem to tally with the image.

    In the image you appear to have multiple values in multiple cells but the code only refers to one cell, A1, which according to the image only has one value in it.

    PS When posting code please use code tags - kind of a forum rule.

  8. #8
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Copy / Paste a range from Excel to a textbox in IE

    Hi Norie,
    The code applies to the image Capture_NEW.PNG. Sorry for that.
    Basically, you are right. I just want to put the values all together at once into the textbox not comma-separated, but separated with a line-break
    Sorry for not sticking to the rules.


    Sub Fill_Form()
    Dim IE As Object
    Dim arr As Variant

    Const DELIMITER = vbCr
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate "http://www.example.com/"
    Do Until IE.readystate = 4
    DoEvents
    Loop
    With ActiveSheet
    arr = WorksheetFunction.Transpose(.Range(.[A1], .Cells(Rows.Count, "A").End(xlUp)))
    If Not IsArray(arr) Then arr = Array(arr)
    IE.document.getElementById("Textarea1").Value = Join(arr, DELIMITER)
    End With
    End Sub
    The result of the attached code looks like Result.PNG. As I said, comma should be replace by newline.
    Attached Images Attached Images

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Copy / Paste a range from Excel to a textbox in IE

    arr is only going to have 1 value ,"'EP1024135A1', ..., 'EP1061075A2'".

    Try replacing the commas in A1 with vbCrLf using the Replace function.
    Please Login or Register  to view this content.
    Last edited by Norie; 08-29-2013 at 05:16 AM.

  10. #10
    Forum Contributor
    Join Date
    10-06-2012
    Location
    Basel, Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Copy / Paste a range from Excel to a textbox in IE

    Hi Norie,
    Thank you, thank you, thank you
    N

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy text from activeX textbox and paste into excel
    By montecarlo2079 in forum Word Formatting & General
    Replies: 29
    Last Post: 07-25-2013, 03:48 PM
  2. [SOLVED] Copy First Three Letters Of Some Textbox And Paste It to Another textbox
    By vijaynadiad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2013, 01:08 PM
  3. [SOLVED] Copy First Three Letters Of Some Textbox And Paste It to Another textbox
    By vijaynadiad in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-08-2013, 03:46 PM
  4. copy and paste from textbox to cell
    By dyodyo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-29-2011, 02:07 AM
  5. Copy TextBox Value to a range in Excel
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2007, 06:37 AM

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