Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2016, 09:25 PM
PRA007's Avatar
PRA007 PRA007 is offline How to put HTML in word clipboard for pasting it as formatted Text Windows 7 64bit How to put HTML in word clipboard for pasting it as formatted Text Office 2010 32bit
Competent Performer
How to put HTML in word clipboard for pasting it as formatted Text
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default How to put HTML in word clipboard for pasting it as formatted Text


Since, I got suggestion for my this post, https://www.msofficeforums.com/word-...data-word.html, I was able to extract web data from word as HTML or as palin text. I searched, but I think there is no method available for Microsoft word user to insert formatted text from HTML especially when the html contains images.

While searching I found out that windows clipboard should contains following format to be pasted as formatted text.

Code:
Version:0.9
    StartHTML:71
    EndHTML:170
    StartFragment:140
    EndFragment:160
    StartSelection:140
    EndSelection:160
    <!DOCTYPE>
    <HTML>
    <HEAD>
    <TITLE> The HTML Clipboard</TITLE>
    <BASE HREF="http://sample/specs">
    </HEAD>
    <BODY>
    <UL>
    <!--StartFragment -->
    <LI> The Fragment </LI>
    <!--EndFragment -->
    </UL>
    </BODY>
    </HTML>
On MSDN, https://support.microsoft.com/en-us/kb/274326, there is method to put html in clipboard using visual basic, but it is very difficult to be understood by word-vba user(beginner).

There is need for word users to be able to paste HTML string as formatted text.
Reply With Quote
  #2  
Old 01-06-2016, 09:48 PM
gmayor's Avatar
gmayor gmayor is offline How to put HTML in word clipboard for pasting it as formatted Text Windows 10 How to put HTML in word clipboard for pasting it as formatted Text Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,104
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Code:
Selection.PasteAndFormat (wdFormatOriginalFormatting)
will paste the html as closely as the disparate formats will allow.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 01-07-2016, 01:45 AM
PRA007's Avatar
PRA007 PRA007 is offline How to put HTML in word clipboard for pasting it as formatted Text Windows 7 64bit How to put HTML in word clipboard for pasting it as formatted Text Office 2010 32bit
Competent Performer
How to put HTML in word clipboard for pasting it as formatted Text
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

Sorry for not making it clear.
I am not talking about pasting formatted text from clipboard. I am talking about putting HTML to clipboard in such way recognized by windows clipboard format (code in post 1) to paste it as formatted text.
Reply With Quote
  #4  
Old 01-07-2016, 08:11 AM
gmayor's Avatar
gmayor gmayor is offline How to put HTML in word clipboard for pasting it as formatted Text Windows 10 How to put HTML in word clipboard for pasting it as formatted Text Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,104
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Did you try simply copying the web extract to the clipboard (CTRL+C) then use the macro?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 01-07-2016, 10:21 PM
PRA007's Avatar
PRA007 PRA007 is offline How to put HTML in word clipboard for pasting it as formatted Text Windows 7 64bit How to put HTML in word clipboard for pasting it as formatted Text Office 2010 32bit
Competent Performer
How to put HTML in word clipboard for pasting it as formatted Text
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

Yes sir. It give plain html if copy paste the web extract. Web extract is in HTML formate like

My StrTxt contains

Code:
<DIV class=someclass>
<DIV id=class-00001 class=class num="00001">
so many such lines with <src = embedded image>
<DIV></DIV>
I want to convert this to

Code:
so many such lines with (inline embedded image).
from web I got little bit of solution.

Code:
Set IE = CreateObject("InternetExplorer.Application")
With IE
	.Visible = False
    .navigate "about:blank"
    .Document.body.innerHTML = StrTxt
    .Document.execCommand "SelectAll"
    .Document.execCommand "Copy"
    .Quit
    .Quit 'to make sure.
End With
Set IE = Nothing
    Set Rng = Tbl.Cell(i, 5).Range
        Rng.Collapse wdCollapseStart
        Rng.PasteAndFormat wdPasteDefault
	Set Rng = Nothing
Reply With Quote
Reply

Tags
vba, wordvba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a oval shape in word and pasting image into it from clipboard choper Word VBA 5 06-15-2015 01:04 AM
How to put HTML in word clipboard for pasting it as formatted Text Shift key is pasting from clipboard...WHY? nc1105 Word 2 01-02-2014 11:57 PM
Pasting image captured with a java program 'on to clipboard' into MSWord 2007 is blur tarunkumarreddy Word 0 02-03-2012 09:42 PM
Import formatted text from Word into PowerPoint parboy PowerPoint 0 07-06-2011 08:52 AM
How to make page footers in html formatted .doc file? equalizer700 Word 0 01-27-2011 02:30 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft