Link to home
Start Free TrialLog in
Avatar of havyn
havyn

asked on

Need to automate "Select All" in Internet Explorer and paste into Word document

I have the second half of this working fine.  Here is my code to do that:

<script language="vbscript">                
     Dim objWord          
     Set objWord = CreateObject("Word.Application")    
     objWord.Documents.Add
     
     Dim docRange
     Set docRange = objWord.Documents(1).Content
     docRange.Collapse
     docRange.Paste
     
     objWord.Visible = True    
     objWord.Activate
</script>

What I need to figure out is how to get the entire contents of the IE window into the clipboard.  This is going to include images and tables, so not just text.  I need it to end up looking like a person just selected all in IE, hit copy, then opened a Word document and hit paste (it retains the formatting).  The second half does work and pastes the contents of the clipboard, but I cannot get the first half to work with IE.  I have tried several javascript and vbscript methods, but they do not seem to grab anything but text.  Is there a way to automate IE so that it can grab what I need and copy it to the clipboard?  I am dumping all of my points on this so I hope I can get a solution.  TIA!

Brendan

ASKER CERTIFIED SOLUTION
Avatar of msreekm
msreekm
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Walter Ritzel
Hi, a solution could be this:

<script language="vbscript">
            function copyToWord()

                  document.execCommand "SelectAll"
                  document.execCommand "Copy"
                  
                  Dim objWord
                  Set objWord = CreateObject("Word.Application")

                  objWord.Documents.Add
                  
                  Dim docRange
                  Set docRange = objWord.Documents(1).Content
                  
                  docRange.Paste
                  
                  objWord.Visible = true
            end function
      </script>

and after the body tag:
<script language="vbscript'>
copyToWord
</script>

The only problem that I detect in this is that the document.execCommand called by a button selects only the button.

Hope this helps,

Walter.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial