Sign in to follow this  
Followers 0
boein

Add word attachment in word document

5 posts in this topic

Hi All,

Pasting a word document as a word-object as an icon into an active word document does not seem to work.  When pasting, the content of the word document is pasted instead of the word-file object.  Also word seems to open this "pasted" document resulting in open-file problems when closing word.

I can do it the basic autoit-way using send keys - and focus on windows (focus on word - Paste special - Paste as file display as icon) ...  but I would prefer using COM-objects.

This is what I have so far.  It works but whatever datatype I try word always pastes the content and opens that document, I only want the pasted word as an embedded object.

Anybody ideas?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

$obj=Objget("","Word.Application")
$obj.visible = true
$ad=$obj.activedocument
_ClipPutFile ( "c:testdoc.doc")
$ad.range.pastespecial DisplayAsIcon:=true, datatype:=1

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the forum!

Did you have a look at the Word UDF that comes with AutoIt? Makes working with Word much easier.

Another hint: Please enclose script code in AutoIt code tags (the blue "A") in the editor. Will greatly enhance readability.

I will have a look at your problem as soon as I get to a computer with Word installed.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

AutoIt does not support parameters by name. So you need to specifiy all parameters in sequence. Parameters you do not want to specify need to be replaced with the "Default" keyword.

Global Const $wdPasteOLEObject = 0
; Method: PasteSpecial(IconIndex, Link, Placement, DisplayAsIcon, DataType, IconFileName, IconLabel)
$ad.range.PasteSpecial(Default, Default, Default, True, $wdPasteOLEObject)

I'm not sure you want to copy the file as RTF but as OLE.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

AutoIt does not support parameters by name. So you need to specifiy all parameters in sequence. Parameters you do not want to specify need to be replaced with the "Default" keyword.

Global Const $wdPasteOLEObject = 0
; Method: PasteSpecial(IconIndex, Link, Placement, DisplayAsIcon, DataType, IconFileName, IconLabel)
$ad.range.PasteSpecial(Default, Default, Default, True, $wdPasteOLEObject)

I'm not sure you want to copy the file as RTF but as OLE.

Thanks for pointing me to the right direction

$ad.range.PasteSpecial(Default, Default, Default, True, $wdPasteOLEObject) did not work, not all parameters were used ("iconlabel" in this case)

using  $ad.range.PasteSpecial (Default, Default, Default, True, Default,Default,Default) instead did the trick.

Regards,

Boein

Edited by boein

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0