FileRead Word .docx. COM_L line 40 error.
I am looking to copy the formatting, font and text content of a MS Word document into a variable and paste it in to an Outlook email. MS to MS.
The FileRead code allows me to read from the docx file, but the contents get bejuggered. Script works perfectly fine with a .txt file, and this makes sense to me because of the encoding and formatting and such.
I got COM_L today, to go with my shiny AHK_L. After reading over a dozen search results, I am still unable to find a solution to have COM copy the text/format from Word into a variable.
I keep getting a 'line 40' error, with both Ansi and Unicode COML files. Something about ppv or pvv. (Have to check, file is at work). There are several good examples online that I've found, but COM keeps giving me the line 40 error when #Included COM_L in my little script.
I've read a few posts that hint that 'com' is not needed when using ahk_L because it is built in somehow, but when I run the COM commands I've found, without the COM include, I get the unknown command error.
Are you sure you're using AutoHotkey_L?MsgBox, % A_AhkVersion
So I had/have AHK_L installed. I downloaded AHK_Basic for the NP++ AHK love....
So since then, I've been running/working in Basic and Not L???
Sad part is, if you never said that... i'de have run into 5,000 other issues down stream and never known why. :shock:
So, I should be able to uninstall/delete AHKB, and this should work, because AHKL will remain.
Firstly, thank you about the AHKL and AHKB heads up. That was something I would have overlooked forever, and was a silly mistake.
So it is now able to copy the contents of my word document, and paste them to Outlook when needed, but the original formatting (font size, style etc) do not come over.
All of the text gets converted to size 10 plain font.
I spent some time searching, but was unable to find anything related to formatting like this.
Do I need to edit my source .docx files, HTML style, and have things in braces? Or should there be a way to copy format style directly.
Conditional Style Objects
Word Objects etc
What would my need fall under? I still haven't been able to find anything on the forum, and none of the 'objects' are giving me too much helpful information.
All I want to do is copy this kind of formatting from Word docs and paste it into an Outlook email, but all I get is plain text when I paste it instead of it looking like this with the different kind of formats.
#SingleInstance Force #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. FoldPath := "\\aaa\users$\" A_UserName "\My Documents\bbb" FileName := "emA.docx" P := FoldPath . FileName ::/ema:: ;;;copies raw text, loses all formatting xx := ComObjGet(P).Range.Text SendInput, %xx% ;;;Does nothing ;xx := ComObjGet(P).Range.Copy ;SendInput, %xx% ;;;Copies raw text, loses all formatting ;ComObjGet(P).Range.Copy ;SendInput, %Clipboard% Return ExitApp
It seems like you can hardcode formatting into a script, telling certain lines to have certain characteristics, but this is not an ideal solution. My goal is to avoid needing to open 10+ word files, finding the doc i need, selecting and copying all text and pasting into an email.
You would want to paste, not SentInput.;;;Copies raw text, loses all formatting ;ComObjGet(P).Range.Copy ;SendInput, %Clipboard% Return
FilePath := "C:\MyDocument.docx" F1:: oDoc := ComObjGet(FilePath) oDoc.Range.FormattedText.Copy oDoc.Close(0) Send, ^v returnEDIT: just to note that this code is addressed to AHKL Noob who wants to copy formated text from Word doc and paste it as formated text
You would want to paste, not SentInput.
Send, ^v worked!!
Can't remember why I had the 'SendInput' in there though.
Random sub-question. What is the different between "Send, %clipboard%" and "Send, ^v" You are pasting the contents of the clipboard in either case, why does the control-v option respond differently from the 'send the contents of the clipboard' command?
Clipboard is a built-in variable that reflects the current contents of the Windows clipboard if those contents can be expressed as text.