Results 1 to 13 of 13

Thread: How to fill up a Text Area on a webpage by VBA ?

  1. #1

    Thread Starter
    New Member Supernova's Avatar
    Join Date
    Oct 2013
    Posts
    9

    Unhappy How to fill up a Text Area on a webpage by VBA ?

    Hello all

    I am trying to fill text in the Text area of the sharepoint page using Excel VBA. Please help me with the same. I am not able to fill this up.

    Given below is the screen shot of the website part which I want to fill up. Above text box is a tool bar which activates when I click on textbox - it's some kind of RichText formatting :


    Name:  image002.JPG
Views: 2694
Size:  15.1 KB


    And HTML code of above section:


    HTML Code:
    <TD valign="top" class="ms-formbody" width="400px">
            <!-- FieldName="Solution"
                 FieldInternalName="Solution"
                 FieldType="SPFieldNote"
              -->
                <span dir="none">
            <span dir="ltr">
                <textarea name="ctl00$m$g_1d93900d_bbd3_47c9_a907_6b574d8362ca$ctl00$ctl04$ctl23$ctl00$ctl00$ctl04$ctl00$ctl00$TextField" rows="6" cols="20" id="ctl00_m_g_1d93900d_bbd3_47c9_a907_6b574d8362ca_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_ctl00_TextField" title="Solution" class="ms-long" dir="none">OLD TEXT</textarea>
                <input name="ctl00$m$g_1d93900d_bbd3_47c9_a907_6b574d8362ca$ctl00$ctl04$ctl23$ctl00$ctl00$ctl04$ctl00$ctl00$TextField_spSave" type="HIDDEN" id="ctl00_m_g_1d93900d_bbd3_47c9_a907_6b574d8362ca_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_spSave" />
            </span>
        <script>if (browseris.ie5up && browseris.win32 && !IsAccessibilityFeatureEnabled())
    {RTE_ConvertTextAreaToRichEdit("ctl00_m_g_1d93900d_bbd3_47c9_a907_6b574d8362ca_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_ctl00_TextField", true,
     false, "", "1033", null, null, null, null, null,"Compatible", "\u002fsites\u002fgdm\u002fNABPS\u002fIncidents",null,null,null,null);}else{DanaMethodWrite("write",document,"&nbsp;<br><SPAN class=ms-formdescription><a href='javascript:HelpWindowKey(\"nsrichtext\")'>Click for help about adding basic HTML formatting.</a></SPAN>&nbsp;<br>");};</script><script> if(DanaFlushWrite) DanaFlushWrite();
    </script></span>
                
                
            </TD>
    The following code does not work with textbox. Doing the opposite, I can import textbox text into excel, but not otherwise! Why?
    Please advise how do I achive the same. Here is my code :

    Code:
        
    
      Dim IE As Object
      Dim objCollection As Object
      Dim objElement As Object
      
          Set IE = CreateObject("InternetExplorer.Application")
          IE.Visible = True
          IE.Navigate "webpage"
                
            
            Do Until IE.ReadyState = READYSTATE_COMPLETE
            Loop
    
        Set objCollection = IE.document.getElementsByTagName("textarea")
        i = 0
        While i < objCollection.Length
            If objCollection(i).Name= "Solution" Then
                objCollection(i).onmouseclick
                objCollection(i).Value = "NEW TEXT"
            End If
            i = i + 1
        Wend
    Last edited by Supernova; Oct 19th, 2013 at 08:47 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to fill up a Text Area on a webpage by VBA ?

    If objCollection(i).Name = "Solution" Then
    the name of textarea is not solution
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member Supernova's Avatar
    Join Date
    Oct 2013
    Posts
    9

    Re: How to fill up a Text Area on a webpage by VBA ?

    Ok I changed to title but code still does not work :

    Code:
        
    
      Dim IE As Object
      Dim objCollection As Object
      Dim objElement As Object
      
          Set IE = CreateObject("InternetExplorer.Application")
          IE.Visible = True
          IE.Navigate "webpage"
                
            
            Do Until IE.ReadyState = READYSTATE_COMPLETE
            Loop
    
        Set objCollection = IE.document.getElementsByTagName("textarea")
        i = 0
        While i < objCollection.Length
            If objCollection(i).Title= "Solution" Then
                objCollection(i).onmouseclick
                objCollection(i).Value = "NEW TEXT"
            End If
            i = i + 1
        Wend
    Last edited by Supernova; Oct 19th, 2013 at 08:50 AM.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to fill up a Text Area on a webpage by VBA ?

    your code works fine with a standard textarea

    as i do not have a sharepoint account, i can not try

    i tested using this page as a sample, to fill this quick reply box, where it turns out there are 3 textareas, 2 of which are not visible
    all 3 contain the same value, but only one will update the content
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member Supernova's Avatar
    Join Date
    Oct 2013
    Posts
    9

    Re: How to fill up a Text Area on a webpage by VBA ?

    Hello westconn1,

    I'm starting to doubt if it is a typical textbox at all - I checked again with the webpage (it has 2 Rich-Text texboxes) and the macro is inputing text to all usual texboxes but not to ANY of these Rich-Texted.....code fails.

    Name:  1_f.jpg
Views: 3122
Size:  17.7 KB

    it seems for me that below part of the html is messing this :


    HTML Code:
    	<script>if (browseris.ie5up && browseris.win32 && !IsAccessibilityFeatureEnabled())
    {RTE_ConvertTextAreaToRichEdit("ctl00_m_g_1d93900d_bbd3_47c9_a907_6b574d8362ca_ctl00_ctl04_ctl23_ctl00_ctl00_ctl04_ctl00_ctl00_TextField", true, false, "", "1033", null, null, null, null, null,"Compatible", "\u002fsites\u002fgdm\u002fNABPS
    \u002fIncidents",null,null,null,null);}else{DanaMethodWrite("write",document,"&nbsp;<br><SPAN class=ms-formdescription>
    <a href='javascript:HelpWindowKey(\"nsrichtext\")'>Click for help about adding basic HTML formatting.</a></SPAN>&nbsp;<br>");};</script><script> if(DanaFlushWrite) DanaFlushWrite();
    </script>

    "ConvertTextAreaToRichEdit" it says.....I'm just trying to get to the bottom of this....does this part of the code makes that texbox is no longer a 'textbox' for VBA ? And that is why it fails ?

    Is there any way to disable executing above code between <script> & </script> in IE ?
    Of course I mean the situation I could still be using VBA.
    Last edited by Supernova; Oct 19th, 2013 at 09:19 PM.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to fill up a Text Area on a webpage by VBA ?

    without a sharepoint page to test on, unlikely i can determine the problem

    i doubt that disabling the script will be useful
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    New Member Supernova's Avatar
    Join Date
    Oct 2013
    Posts
    9

    Re: How to fill up a Text Area on a webpage by VBA ?

    Digging I found more insight about this :
    http://sharepointerz.blogspot.com/20...t-control.html
    http://bloggingabout.net/blogs/jpsmi...5/30/4957.aspx


    As the sharepoint is access restricted I can send you page source code only.

    In a meantime here is a page which source code regarding my problem is almost very same, can you try on this to put a text to Description textbox ?

    http://www.adfreeclassifieds.com/publish-a-new-ad.htm
    Last edited by Supernova; Oct 20th, 2013 at 12:46 AM.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to fill up a Text Area on a webpage by VBA ?

    Code:
    Set f = ie.document.frames(0)
    Set txt = f.document.all(8)
    txt.innertext = "asdasdfasdf"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    New Member
    Join Date
    Nov 2017
    Posts
    2

    Re: How to fill up a Text Area on a webpage by VBA ?

    Im solving same problem(For now I have workaround in Access by filling it directly into Table by SQL,but not everywhere may do it directly). That metod with frames didnt work for me, found only one editable frame but it wasnt that textarea, but give me Idea. I tried before Seting IE.Document, select that text area and look into Active Element . And figure out it is realy not same object what you can find in html code. Found this ID, its similar but with iframe on end.
    Code:
    "ctl00_m_g_25a6b7b2_9f4c_4c89_b015_ae1bc9d2ae2b_ctl00_ctl05_ctl05_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_iframe"
    So it is really Frame, but .value or .innertext filling still dont work.
    Only one what do some change is .outertext
    Code:
        Set htmldoc = IE.Document
                With htmldoc
           Set f = .getElementById("ctl00_m_g_25a6b7b2_9f4c_4c89_b015_ae1bc9d2ae2b_ctl00_ctl05_ctl05_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_iframe")
          'on first try select field by hand before setting  IE.Document  and uncoment this ( then take your ID from f object)'  Set f = .activeElement
           f.outerText = "html"
    Fun Part... Frame dissapear but text will shown up. But still dont work ,it not save anything. I will keep trying that. I think there is more children objects . Just find that right one.

  10. #10
    New Member
    Join Date
    Feb 2018
    Posts
    1

    Re: How to fill up a Text Area on a webpage by VBA ?

    Anybody got the answer to the above query, I'm stuck at the same point.

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to fill up a Text Area on a webpage by VBA ?

    this is a really old thread, probably with little relevance to current versions of internet explorer, you should have started a new thread, as should have linxcz previously

    the html code for a single element is of little use to try to figure out what may work, without access to the web site no testing is possible, maybe if you supply much more information........
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,039

    Re: How to fill up a Text Area on a webpage by VBA ?

    I agree that you should start a new thread on this. Not only is there a chance that the technology has changed, but the point to the forum is to get the most eyes on the question that you can, which you can do best by starting a new thread with a question, since this thread did not answer your question. Just write a complete and thorough description of the problem.
    My usual boring signature: Nothing

  13. #13
    New Member
    Join Date
    Nov 2017
    Posts
    2

    Re: How to fill up a Text Area on a webpage by VBA ?

    Quote Originally Posted by Shaggy Hiker View Post
    I agree that you should start a new thread on this. Not only is there a chance that the technology has changed, but the point to the forum is to get the most eyes on the question that you can, which you can do best by starting a new thread with a question, since this thread did not answer your question. Just write a complete and thorough description of the problem.
    Try Selenium. It worked for me. With that library you can fill it.

Posting Permissions

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



Click Here to Expand Forum to Full Width