Using Clipboard HTML

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
colin.rogers
Newbie
Posts: 11
Joined: Sat Oct 28, 2017 11:49 am

Using Clipboard HTML

Post by colin.rogers » Wed Oct 24, 2018 2:28 pm

Hi team,

We would appreciate your thoughts and any guidance please on this scenario. The background is we are trying to preserve HTML formatting via the Windows clipboard.

As a test:
We use manual Windows CTRL-C to copy HTML from a webpage onto the clipboard.
We then use manual Windows CTRL-V to paste that into a form (in this specific case a Windows 10 Create Mail body).
We repeat the manual paste several times and the HTML formatting is preserved from the clipboard - so far so good.
We then ask MS to perform the following functions:

Wait>5
//Paste 1
Press CTRL
SendText>{"v"}
Release CTRL
WaitClipBoard
GetClipBoard>strClipBoard,0
WaitClipBoard
Wait>1
PutClipBoard>strClipBoard
WaitClipBoard
Wait>5
//Paste 2
Press CTRL
SendText>{"v"}
Release CTRL

Paste 1 preserves the formatted HTML.
Paste 2 displays the text but loses the formatting - not the result we were hoping for.
If we perform the GetClipBoard function with "1" at the end instead of "0" it then displays the raw HTML plus the Windows clipboard header.

Is there any way of preserving the formatted HTML in Paste 2 ?

Thank you.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Using Clipboard HTML

Post by Marcus Tettmar » Mon Oct 29, 2018 1:54 pm

PutClipboard just puts text on the clipboard. There's no option to do anything else.

But simulating CTRL+C will do whatever happens manually.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

colin.rogers
Newbie
Posts: 11
Joined: Sat Oct 28, 2017 11:49 am

Re: Using Clipboard HTML

Post by colin.rogers » Tue Oct 30, 2018 10:22 am

Many thanks, Marcus, for confirming the text-only nature of PutClipBoard.

The query was raised because the HTML comes in from an MS VBScript function which has collected it directly from an email Body.

In principle, we think it is possible to put HTML onto the Windows clipboard using CF_HTML and composing the necessary header. However, for others in the same position using MS our workaround suggestion is probably something like this.

//Assuming HTML is already on the clipboard or in a variable
GetClipBoard>strClip,1
Length>strClip,nLength
//Remove HTML header
MidStr>strClip,96,nLength,strSub
//Use workaround
DeleteFile>C:\Users\colin\Documents\clipboard.htm
WriteLn>C:\Users\colin\Documents\clipboard.htm,nWLNRes,strSub
RunProgram>C:\Program Files (x86)\Internet Explorer\iexplore.exe C:\Users\colin\Documents\clipboard.htm
//Simulate manual actions
Wait>1
Press CTRL
SendText>{"a"}
SetFocus>Inbox - Soitron ‎- Mail
Wait>1
SendText>{"v"}
Release CTRL
Wait>1

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts