"Paste text into new file", but .doc instead of txt. Possible?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
cadu
Posts: 287
Joined: 18 Mar 2012 21:50

"Paste text into new file", but .doc instead of txt. Possible?

Post 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

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: "Paste text into new file", but .doc instead of txt. Possible?

Post 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;

Last edited by bdeshi on 10 Apr 2017 09:59, edited 1 time in total.
Reason: delete 0, 0, delete 0, 0, $vbsFile;; ==> delete 0, 0, $vbsFile;
One of my scripts helped you out? Please donate via Paypal

cadu
Posts: 287
Joined: 18 Mar 2012 21:50

Re: "Paste text into new file", but .doc instead of txt. Possible?

Post 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?

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: "Paste text into new file", but .doc instead of txt. Possible?

Post by highend »

Afaik not without using an external tool / some ugly hacks in XY / without actually displaying the word document
One of my scripts helped you out? Please donate via Paypal

cadu
Posts: 287
Joined: 18 Mar 2012 21:50

Re: "Paste text into new file", but .doc instead of txt. Possible?

Post by cadu »

Many thanks for all feedback highend!

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: "Paste text into new file", but .doc instead of txt. Possible?

Post 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...
One of my scripts helped you out? Please donate via Paypal

Post Reply