Page 1 of 1
"Paste text into new file", but .doc instead of txt. Possible?
Posted: 10 Apr 2017 02:59
by cadu
Hi,
Similarly to "Paste special > Paste text into new file", which creates a .txt file with clipboard content, is it possible to create a .doc file with text from clipboard by using XYplorer?
Maybe it can be achieved by using a script or any other workaround...
Thanks for info,
Carlos_Cadu
Re: "Paste text into new file", but .doc instead of txt. Possible?
Posted: 10 Apr 2017 08:55
by highend
Code: Select all
$documentName = "New Word document.doc";
$fullPath = "<curpath>\$documentName";
$cp = regexreplace(<clipboard>, "[""]", '""');
$content = "";
foreach($line, $cp, <crlf>) {
$content = $content . "objSelection.TypeText " . quote($line) . " &vbNewLine" . <crlf>;
}
$vbs = <<<>>>
' Create a word Document
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Set objDoc = objWord.Documents.Add()
' Add content
Set objSelection = objWord.Selection
$content
' Save it
objDoc.SaveAs("$fullPath")
objWord.Quit
>>>;
$vbsFile = "%TEMP%\~CreateWordDocument.vbs";
writefile($vbsFile, $vbs);
runret("""cscript"" ""$vbsFile"" //nologo");
delete 0, 0, $vbsFile;
Re: "Paste text into new file", but .doc instead of txt. Possible?
Posted: 10 Apr 2017 14:36
by cadu
Many thanks for the script Highend!
It worked, and the only issue is that text formatting is being removed, as showed here:
https://goo.gl/HZshA0
My main reason to create a .doc file (instead of .txt) is to keep text formatting.
Is possible to adjust the script to create .doc keeping text content formatted?
Re: "Paste text into new file", but .doc instead of txt. Possible?
Posted: 10 Apr 2017 14:54
by highend
Afaik not without using an external tool / some ugly hacks in XY / without actually displaying the word document
Re: "Paste text into new file", but .doc instead of txt. Possible?
Posted: 10 Apr 2017 19:56
by cadu
Many thanks for all feedback highend!
Re: "Paste text into new file", but .doc instead of txt. Possible?
Posted: 10 Apr 2017 20:32
by highend
Could be done rather easily e.g. with AHK / AutoIt.
AHK can access COM, so it's easy to create the document and it shouldn't have any problems
to paste the clipboard into the word window...