mrthomas

How to insert(replace) text into a word document textbox?

31 posts in this topic

I tried for a couple of hours to insert(replace) a text from a word document(.doc) without results. The function _WordDocFindReplace don't find the text from textboxes. I need an example script, how to find and replace the text from word documents textbox. Thanks

Share this post


Link to post
Share on other sites



If I find out you have PMed other people besides me you are going to regret your decision to send unsolicited PMs to random people. I strongly suggest you read the forum rules now before you make additional mistakes that lead to your removal from this forum.

Share this post


Link to post
Share on other sites

Sorry for those PMs, but I really need help as soon as possible. Will not happen again. I am still waiting for help. Thanks

Share this post


Link to post
Share on other sites

It would help your cause if you posted some code we all could look at, as 9 times out of 10 it's the users implementation rather than the function.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

I don't know how to start. I only want to know how can I write something with autoit to word textboxes added by me manually.

Share this post


Link to post
Share on other sites

But in your first post you noted that you tried "for hours". What is the result (code) of this attempts?


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

Yes, i tried with pieces of codes that i found on internet, to make only a functions that could write on textboxes from a word document.. but nothing that could work.

This is the code for find and replace text in a word document, but this don't find text from textboxes inside de word document:

include <Word.au3>
$oWordApp = _WordCreate (@ScriptDir & "\1.doc")
$oDoc = _WordDocGetCollection($oWordApp, 0)
$oFind = _WordDocFindReplace($oDoc, "this", "THIS")
If $oFind Then
    MsgBox(0, "FindReplace", "Found and replaced.")
Else
    MsgBox(0, "FindReplace", "Not Found")
EndIf
_WordQuit ($oWordApp, 0)

thanks

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

If you run your script from SciTE do you get any errors in the Output pane?

Edited by water

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

No. I only get this:

--> Word.au3 Warning from function _WordDocFindReplace, $_WordStatus_NoMatch
>Exit code: 0    Time: 3.558

Share this post


Link to post
Share on other sites

What version of AutoIt do you use?

What version of Office do you use (Word 2007, 2010)?

What flavor of Office do you use (32 or 64 bit)?

Is it a .doc or .docx file?

What operating system do you run (32 or 64 bit)?


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

I use AutoIT v3.3.8.1, Office 2010 at 32 bit. I tried with .doc, and with .docx too. My operating system that i run is 64 bit.

Share this post


Link to post
Share on other sites

Do you compile the scripts for 32 or 64 bit. Press Ctrl+F7 in SciTE and check the output arch.

As your Office is 32 bit you need to compile your Autoit scripts for 32 bit too.


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

I compiled the script at 32 bit, then at 64 bit, and nothing. _WordDocFindReplace is working, but only with the text that is in the document. the text from textboxes can't be found.. i don't know how i find and replace text from word documents textboxes...

Share this post


Link to post
Share on other sites

I think it's a limitation. I found it failed when i was writing this functionality a while back. If the documents are under your control, you could try using a table rather than a text box.

It may be something about the S&R function looking only at range.text rather than range.wholestory - but that's beyond me in terms of suggestions to make it work.

William

Share this post


Link to post
Share on other sites

I can't make it with table because i need to put same text over the original text.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

It will work in a table, but definitely not in a text box.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Ok. I understand. AutoIT can't write or read in word documents textboxes. I will try something else, with tables, like your advice.

Edit: I solved with Tables.

Thank you very much for your time community!

Edited by mrthomas

Share this post


Link to post
Share on other sites

There is a solution for finding and replacing text in textboxes in Word.

_Word_DocFindReplace won't find it directly, but you can select the textboxes through the UDF and then the replace function works.

To select a Word textbox do this:

$WordObject=_Word_Create ()
$WordDocObject=_Word_DocOpen ($WordObject, "test.doc")
$WordObject.ActiveDocument.Shapes($nYourTextBoxNumber).Select
_Word_DocFindReplace($WordDocObject, "FindMe", "ReplaceMe")

 

 

1 person likes this

Share this post


Link to post
Share on other sites

This thread has been dead for 4 years and the OP has been absent for more than 3 years. So I'm not sure any one will get your message ;)


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

Well, I stumbled across this thread searching for a solutions and others might as well... I thought I should share the solution.

But I get your point... :-)

BTW thanks for the UDF. It completely amazes me that you are actually not limited to the functions given by the UDF directly, but by opening a Word object it is possible to actually use ALL the word items/objects that can be found in Word VBA scripts and macros. That way you can virtually doing everything in Word from Autoit. Great concept!

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