Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

FileRead Word .docx. COM_L line 40 error.


  • Please log in to reply
15 replies to this topic
AHKL noob
  • Guests
  • Last active:
  • Joined: --
I am new to the AHK_L world and have run into my first real issue.

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.





Thoughts :?:

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
MsgBox, % ComObjGet("[color=red]<full workbook path>[/color]").Range.Text


CodeKiller
  • Members
  • 2067 posts
  • Last active: Feb 26 2016 09:30 AM
  • Joined: 10 Jul 2008
True : COM is no longer needed with AHK_L, it alreadyu includes Com support, however the syntaxe is no more the same (but close enough).

AHKL noob
  • Guests
  • Last active:
  • Joined: --
Thank you both. Will give this a shot when I get in. :)

AHKL noob
  • Guests
  • Last active:
  • Joined: --

MsgBox, % ComObjGet("[color=red]<full workbook path>[/color]").Range.Text


So now I keep getting:

The following cariable name contains an illegal character: ".Range.Text" when running the msgbox example above.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Are you sure you're using AutoHotkey_L?

MsgBox, % A_AhkVersion


AHKL Noob
  • Guests
  • Last active:
  • Joined: --

Are you sure you're using AutoHotkey_L?

MsgBox, % A_AhkVersion


Holy hell...

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.

AHKL Noob
  • Guests
  • Last active:
  • Joined: --
So I finally got some free time to play with this.

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.

AHKL Noob
  • Guests
  • Last active:
  • Joined: --
So i've been looking for a solition to my formatting issue in the MSDN page for application objects: (http://msdn.microsof... ... =office.12).aspx) with no luck.

Application Objects
Conditional Style Objects
Document Objects
Documents Objects
Font Objects
TextRetrievalMode 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.



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Have you tried just copying & pasting?

Copy Method may be useful.

Carcophan
  • Members
  • 1578 posts
  • Last active: Nov 27 2013 06:46 PM
  • Joined: 24 Dec 2008
Was playing around with this and am also having issues.


#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.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

;;;Copies raw text, loses all formatting 
;ComObjGet(P).Range.Copy  
;SendInput, %Clipboard% 
Return 

You would want to paste, not SentInput.

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
Press F1.
FilePath := "C:\MyDocument.docx"

F1::
oDoc := ComObjGet(FilePath)
oDoc.Range.FormattedText.Copy
oDoc.Close(0)
Send, ^v
return
EDIT: 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

Carcophan
  • Members
  • 1578 posts
  • Last active: Nov 27 2013 06:46 PM
  • Joined: 24 Dec 2008

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?

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

Clipboard is a built-in variable that reflects the current contents of the Windows clipboard if those contents can be expressed as text.