Jewtus Posted August 31, 2015 Share Posted August 31, 2015 (edited) I'm trying to attach a file to a word document (the same way you would if you click insert --> Object --> Create from file --> Display as icon)I've tried to do:$oWord=ObjCreate("Word.Application") $oWord.Visible = True $oDoc=$oWord.Documents.Add('',False,0) ;$WdNewBlankDocument $oSelection=$oWord.Selection With $oSelection .InsertFile($filename,Default,False,False,True) endwithand that works but it doesn't create the icon style (so not really what I'm trying to do. I did some hunting around and I found this:https://msdn.microsoft.com/en-us/library/office/ff195728.aspxWhich appears to be the correct function but it doesn't seem to work when I try it:$oWord=ObjCreate("Word.Application") $oWord.Visible = True $oDoc=$oWord.Documents.Add('',False,0) ;$WdNewBlankDocument $oSelection=$oWord.Selection With $oSelection .OLEObjects.Add(Default,$filename,Default,Default,True,"File") endwithBut I get an unknown name error (80020006). Any idea what I'm doing wrong?? EDIT Upon further investigation it looks like the type is ignored if a file name is given and vice versa. I'm not sure how I need to do this, but everything I'm reading says that this: .OLEObjects.Add Filename:={Filename}, Link:=False, DisplayAsIcon:=True, IconFileName="ThisIsATest"should work, I just don't know how to make that execute in autoit Edited August 31, 2015 by Jewtus Link to comment Share on other sites More sharing options...
water Posted August 31, 2015 Share Posted August 31, 2015 Will have a look at it next week. I'm on vacation right now. Jewtus 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Jfish Posted September 1, 2015 Share Posted September 1, 2015 The OLEObjects.Add method you referenced is for Excel. I haven't seen one for Word (though logically I would think it should exist). Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Danyfirex Posted September 1, 2015 Share Posted September 1, 2015 maybe this is what you need. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Jfish Posted September 1, 2015 Share Posted September 1, 2015 @Danyfirex - I think that embeds a Word doc to an Excel sheet. Excel supports the OLEObjects.Add method. The question is can you do it in reverse? I don't see that method on the Word Object Reference Model. The closest I have found is the Dialogs object that supports inserting the object. However, I don't think you can bypass the dialog - or at least I have not figured it out just yet . Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Jewtus Posted September 1, 2015 Author Share Posted September 1, 2015 (edited) @Jfish, I have seen some example on a few different message boards and they all seem to have the syntax as (the other boards often say excel/word so I assume the function is in both).OLEObjects.Add filename:="C:\Filename.pdf" link:=False DisplayAsIcon:=TrueWhich I can understand, but I don't know how to structure that call in autoit to make it work.I too found the dialog but that is what I'm trying to avoid. The MSDN says the syntax is:.Add(ClassType, FileName, Link, DisplayAsIcon, IconFileName, IconIndex, IconLabel, Left, Top, Width, Height)If this is a function just limited to Excel, how would I insert a file as an object? It seems like it should be an option given that you can add word or excel files (not as icons) using vb... Essentially what I'm trying to get my script to do is rebuild a word doc of some data from a database and attach the supporting documents from the network. Edited September 1, 2015 by Jewtus Link to comment Share on other sites More sharing options...
Jfish Posted September 1, 2015 Share Posted September 1, 2015 @Jewtus - It may also be a word function - but I have not found it after reviewing the object model reference and Googling it. I agree, it should be there. @Water may be able to pinpoint the correct function when he gets back from vacation. That said, you may not be able to make that function work if there is no object for it in Word. Were you able to find it on MSDN for Word? Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Danyfirex Posted September 1, 2015 Share Posted September 1, 2015 (edited) Look: Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") $objWord = ObjCreate("Word.Application") $objWord.Visible = True $objDoc = $objWord.Documents.Add() $objSelection = $objWord.Selection Local $sMyPDF="C:\Users\User\Desktop\17598007.pdf" $objSelection.InlineShapes.AddOLEObject("",$sMyPDF) Saludos Edited December 30, 2019 by Danyfirex Jfish 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Jfish Posted September 1, 2015 Share Posted September 1, 2015 Look:Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") $objWord = ObjCreate("Word.Application") $objWord.Visible = True $objDoc = $objWord.Documents.Add() $objSelection = $objWord.Selection Local $sMyPDF="C:\Users\RAZIEL\Desktop\17598007.pdf" $objSelection.InlineShapes.AddOLEObject("",$sMyPDF, False, False)SaludosWell done! You found it under InlineShapes! Here is the MSDN link https://msdn.microsoft.com/EN-US/library/office/ff835835.aspx Good job @Danyfirex Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Danyfirex Posted September 1, 2015 Share Posted September 1, 2015 (edited) thanks @Jfish If you want custom icon and labelicon. Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") $objWord = ObjCreate("Word.Application") $objWord.Visible = True $objDoc = $objWord.Documents.Add() $objSelection = $objWord.Selection Local $sMyPDF="C:\Users\User\Desktop\17598007.pdf" For $i= 1 to 20 $objSelection.InlineShapes.AddOLEObject("",$sMyPDF,false,True,@SystemDir & "\Shell32.dll",190+$i,"Shell32Icon=" & 190+$i) Next Saludos Edited December 30, 2019 by Danyfirex Jewtus 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Jewtus Posted September 1, 2015 Author Share Posted September 1, 2015 PERFECT!!! Thanks! Link to comment Share on other sites More sharing options...
Danyfirex Posted September 1, 2015 Share Posted September 1, 2015 You're wellcome. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now