+ Reply to Thread
Results 1 to 8 of 8

Need help reading IE textarea using Excel 2010 VBA

Hybrid View

indo583 Need help reading IE textarea... 11-06-2013, 06:12 PM
AlphaFrog Re: Need help reading IE... 11-06-2013, 06:56 PM
indo583 Re: Need help reading IE... 11-08-2013, 11:45 AM
indo583 Re: Need help reading IE... 11-08-2013, 12:39 PM
AlphaFrog Re: Need help reading IE... 11-08-2013, 02:00 PM
indo583 Re: Need help reading IE... 11-12-2013, 05:33 PM
indo583 Re: Need help reading IE... 11-12-2013, 07:24 PM
indo583 Re: Need help reading IE... 11-13-2013, 06:55 PM
  1. #1
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Need help reading IE textarea using Excel 2010 VBA

    Hello,

    I am trying to read the value of a IE8 textarea using Excel 2010 VBA 7. The error I get is: "Object doesn't support this property or method" in relation to this line of code:
    OldNotes = OldNotes.Value

    I have also tried .innerText instead of .Value and get the same error.

    Here is the website source that relates to the textarea:

    <textarea name="ctl00$ContentPlaceHolder1$txtOldNotesIssue" rows="2" cols="20" readonly="readonly" id="ctl00_ContentPlaceHolder1_txtOldNotesIssue" style="height:150px;width:98%;">Text goes here
    </textarea>
    Here is the VBA code I am using to try and read the text area:

    'Microsoft Internet Controls Reference is needed
    'Microsoft HTML Object Library Reference is needed
    
    Public Sub ReadNotes()
    
        Dim objShellWins As SHDocVw.ShellWindows
        Dim objIE As SHDocVw.InternetExplorer
        Dim objDoc As Object
        Dim WebCheck As String
        Dim SuccessCheck As Integer
    
        WebCheck = "CATS"
        SuccessCheck = 0
    
        Set objShellWins = New SHDocVw.ShellWindows
        For Each objIE In objShellWins
            With objIE
                If (InStr(1, .LocationName, WebCheck, vbTextCompare)) Then
                    Set objDoc = .document
                    If (TypeOf objDoc Is HTMLDocument) Then
                        SuccessCheck = 1
                        objIE.Visible = True
    
    '-----------This is the section of code I am having problems with--------------------------------------------------
        
                        Set OldNotes = objIE.document.getElementsByName("ctl00$ContentPlaceHolder1$txtOldNotesIssue")
                        OldNotes = OldNotes.Value
                        MsgBox OldNotes
                        
    '------------------------------------------------------------------------------------------------------------------
    
                    End If
                End If
            End With
        Next
            
        'If the CATS webpage is not found, displays an error message and stops the program
        If SuccessCheck = 0 Then
            MsgBox ("CATS webpage not found." & vbCrLf & vbCrLf _
            & "Navigate to the CATS search page and try again."), vbCritical
            End
        End If
        
    End Sub
    Thanks in advance,
    Matt

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Need help reading IE textarea using Excel 2010 VBA

    Did you declare (Dim) OldNotes somewhere?

    Maybe just try this.
    '-----------This is the section of code I am having problems with--------------------------------------------------
                        Dim Oldnotes As String
                        Oldnotes = objIE.document.getElementsByName("ctl00$ContentPlaceHolder1$txtOldNotesIssue").Value
                        
                        MsgBox Oldnotes
                        
    '------------------------------------------------------------------------------------------------------------------
    Or this...
    '-----------This is the section of code I am having problems with--------------------------------------------------
                        Dim Oldnotes As Object
                        Set Oldnotes = objIE.document.getElementsByName("ctl00$ContentPlaceHolder1$txtOldNotesIssue")
                        
                        MsgBox Oldnotes.Value
                        
    '------------------------------------------------------------------------------------------------------------------
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Need help reading IE textarea using Excel 2010 VBA

    Thanks for your suggestions, but I get the same error: "Object doesn't support this property or method".

    A textarea can be defined as an Object, and .Vaule and .innerText are valid properties, correct?

    I've also tried defining it as an HTMLTextArea and HTMLTextAreaElement. If I don't use "Set Oldnotes" I get an Object variable not set error, if I do use "Set Oldnotes", I get a Type mismatch error.

    The script worked when the data was just in a table, but now that it's in a textarea, it doesn't. I've been trying to solve this for several days with no luck, it’s very frustrating.

  4. #4
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Need help reading IE textarea using Excel 2010 VBA

    Maybe this will help someone figure it out. I've attached a workbook with an example. Just click the "Read Textarea" button and it will open a webpage that has a textarea in it. It will then attempt to read the textarea and display it in a message box, but it will give the error I'm getting. For some reason I am unable to get the Value or innerText of a textarea.

    If you would prefer to create a new workbook, here is the code. Just make sure you add the Microsoft Internet Controls Reference and the Microsoft HTML Object Library Reference in the visual basic editor (Tools->References) or it won't run:

    'Microsoft Internet Controls Reference is needed
    'Microsoft HTML Object Library Reference is needed
    
    Public Sub ReadNotes()
    
        Dim objShellWins As SHDocVw.ShellWindows
        Dim objIE As SHDocVw.InternetExplorer
        Dim objDoc As Object
        Dim WebCheck As String
        Dim SuccessCheck As Integer
        Dim URL1 As String
        Dim strNotes As Object
        
        'Textarea Demonstration Webpage URL and checks to make sure webpage is open
        URL1 = "http://blogs.sitepointstatic.com/examples/tech/textarea-expander/index.html"
        WebCheck = "textarea demonstration"
        SuccessCheck = 0
        
        'Open new webpage and navigate to the "textarea demonstration" webpage
        Set objIE = New SHDocVw.InternetExplorer
        objIE.navigate URL1
        
        'Wait until internet explorer is done loading before proceeding
        Call ExplorerStatusCheck(objIE)
        
        'Check each open tab for the "textarea demonstration" webpage
        Set objShellWins = New SHDocVw.ShellWindows
        For Each objIE In objShellWins
            With objIE
                If (InStr(1, .LocationName, WebCheck, vbTextCompare)) Then
                    Set objDoc = .document
                    If (TypeOf objDoc Is HTMLDocument) Then
                        SuccessCheck = 1
                        objIE.Visible = True
    
    '-----------This is the section of code I am having problems with--------------------------------------------------
                        
                        Set strNotes = objIE.document.getElementsByName("textarea1")
                        strNotes = strNotes.Value
                        MsgBox strNotes
    
    '------------------------------------------------------------------------------------------------------------------
    
                    End If
                End If
            End With
        Next
            
        'If the Textarea Demonstration webpage is not found, displays an error message and stops the program
        If SuccessCheck = 0 Then
            MsgBox ("Textarea Demonstration webpage not found." & vbCrLf & vbCrLf _
            & "Please try again."), vbCritical
            End
        End If
        
    End Sub
    
    'Wait until internet explorer is done loading before proceeding
    Public Sub ExplorerStatusCheck(objIE As SHDocVw.InternetExplorer)
    
        With objIE
            Do While .Busy: DoEvents: Loop
            Do While .readyState <> 4: DoEvents: Loop
            Do Until .Busy = False
            Loop
            While objIE.readyState <> READYSTATE_COMPLETE
                DoEvents
            Wend
        End With
    
    End Sub
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Need help reading IE textarea using Excel 2010 VBA

    This worked for me using your example workbook.

    Public Sub ReadNotes()
    
        Dim objShellWins As SHDocVw.ShellWindows
        Dim objIE As SHDocVw.InternetExplorer
        Dim objDoc As Object
        Dim WebCheck As String
        Dim SuccessCheck As Integer
        Dim URL1 As String
        Dim objNotes As Object
        Dim strNotes As String
        
        'Textarea Demonstration Webpage URL and checks to make sure webpage is open
        URL1 = "http://blogs.sitepointstatic.com/examples/tech/textarea-expander/index.html"
        WebCheck = "textarea demonstration"
        SuccessCheck = 0
        
        'Open new webpage and navigate to the "textarea demonstration" webpage
        Set objIE = New SHDocVw.InternetExplorer
        objIE.navigate URL1
        
        'Wait until internet explorer is done loading before proceeding
        Call ExplorerStatusCheck(objIE)
        
        'Check each open tab for the "textarea demonstration" webpage
        Set objShellWins = New SHDocVw.ShellWindows
        For Each objIE In objShellWins
            With objIE
                If (InStr(1, .LocationName, WebCheck, vbTextCompare)) Then
                    Set objDoc = .document
                    If (TypeOf objDoc Is HTMLDocument) Then
                        SuccessCheck = 1
                        objIE.Visible = True
    
    '-----------This is the section of code I am having problems with--------------------------------------------------
                        
                        Set objNotes = objIE.document.getElementsByName("textarea1")
                        strNotes = objNotes(0).Value
                        MsgBox strNotes
    
    '------------------------------------------------------------------------------------------------------------------
    
                    End If
                End If
            End With
        Next
            
        'If the Textarea Demonstration webpage is not found, displays an error message and stops the program
        If SuccessCheck = 0 Then
            MsgBox ("Textarea Demonstration webpage not found." & vbCrLf & vbCrLf _
            & "Please try again."), vbCritical
            Exit Sub
            'End    ''''Do not the the END statement unless absolutely necessary as it can cause the unexpected
        End If
        
    End Sub
    The use of the END statement was not the problem. Avoiding it is just good practice.

    This was the fix
    strNotes = objNotes(0).Value

    Apparently (not sure) the TextArea returns a collection or an array. So use an index number to specify an element e.g.; objNotes(0)

    Also, you were trying to assign a string to an object variable. That also causes an error. The new code uses an object variable and a string variable.

  6. #6
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Need help reading IE textarea using Excel 2010 VBA

    Thanks for the help. Your suggestion worked on the example I provided. Unfortunately I still get the same error on the website I am trying to pull from. Unfortunately it's an intranet website, so I can't post the exact problem. This is a step in the right direction though. I'll keep plugging away at it and post the solution once I find it.

  7. #7
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Need help reading IE textarea using Excel 2010 VBA

    I think I've narrowed down the problem, but I don't know how to fix it yet. The textarea I am trying to pull a value from is in a popup radwindow. I need to figure out how to get my code to focus on the radwindow.

  8. #8
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Need help reading IE textarea using Excel 2010 VBA

    I'm marking this Thread as solved. The correction by AlphaFrog allows me to get the value of a textarea. My issue now is figuring out how to pull the information I need from a Child Window. I'll start a new Thread, as it is an unrelated issue.

+ 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. Control IE website's "TEXTAREA" - Read & Replace value with VBA in excel.
    By R_S_6 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-19-2013, 01:49 AM
  2. Copying worksheets from excel to word in vba as images
    By papasideris in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-18-2012, 11:32 AM
  3. Searching the particular numberfrom excel'2010 table and locate the number in Word'2010
    By jaffirahamed1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2012, 08:09 AM
  4. [SOLVED] getting value of selected list item in a textarea
    By junoon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-31-2006, 10:55 PM

Tags for this Thread

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