Jump to content

Recommended Posts

Posted

Hi, there.

I'm trying to edit specific text boxes in a Word document, but I'm running into issues because they're grouped? (I think??)

I used the Macro recorder, and it shows:

 

ActiveDocument.Shapes.Range(Array("Group 5")).Select
    ActiveDocument.Shapes.Range(Array("Text Box 8")).Select
    Selection.TypeText Text:="Centre"


Could some kind soul please tell me how to access these in AutoIt?

All assistance gratefully received.

Posted

You can get the shape this way:

 

$oDoc.Shapes("Group 5").GroupItems("Text Box 8")

 

Saludos

Posted
On 3/19/2026 at 6:05 PM, Danyfirex said:

You can get the shape this way:

 

$oDoc.Shapes("Group 5").GroupItems("Text Box 8")

 

Saludos

Thank you for the reply. Sorry I didn't respond before now - I don't get notifications from the forum.

I'll give this a try shortly.

 

Posted

Arghh.. I feel like I'm almost there? My lack of knowledge on using "with" is letting me down..

$test = $oDoc.Shapes("Group 5").GroupItems("Text Box 61").Select

Highlights the textbox in the Word Document...

But how do I change the contents of the text box to be "Hello world"?

Or read the current value of that textbox?

I've tried 

$test = $oDoc.Shapes("Group 5").GroupItems("Text Box 61").Select.TypeText
$test = $oDoc.Shapes("Group 5").GroupItems("Text Box 61").Select.Text
$test = $oDoc.Shapes("Group 5").GroupItems("Text Box 61").Select.TypeText.Text

They all return a blank value.

I know I'm missing something REALLY obvious!!

I've tried using "With ODoc.blah, OWord.blah"... It just throws up errors about the requested action with this object has failed.

 

 

  • Solution
Posted (edited)
$sText = $oDoc.Shapes("Group 5").GroupItems("Text Box 8").TextFrame.TextRange.Text

Should return the text.

You can find an example of how to edit the text in Microsofts Office Reference.

Edited by water

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

 

Posted
13 hours ago, water said:
$sText = $oDoc.Shapes("Group 5").GroupItems("Text Box 8").TextFrame.TextRange.Text

Should return the text.

You can find an example of how to edit the text in Microsofts Office Reference.

Returning the current value worked - thanks!

$Box = $oDoc.Shapes("Group 5").GroupItems("Text Box 8").TextFrame.TextRange
$CurVal = $Box.Text
Msgbox(0, "CurVal", $CurVal)



$Box.Text = "Has this changed?!?!"
$CurVal = $Box.Text
Msgbox(0, "CurVal", $CurVal)


Next questions - SORRY!

I've found that I have two documents types where the text boxes are named slightly differently.

Scenario 1 - Surname=1; Forename=2; ID number=3
Scenario 2 - Surname=8; Forename=11; ID number=15

I can have:
 

$TB=""
For $i in $oDoc.Shapes("Group 5").GroupItems
$TB = $TB & $i.Name & "|"
Next


So I can have

Case $TBList = "Text Box 8|Text Box 11|Text Box 14"
; do population for that scenario.

Case $TBList = "Text Box 1|Text Box 2|Text Box 3"
; do population for that scenario


But.. How can I change the hard-coded variable:

$oDoc.Shapes("Group 5").GroupItems("Text Box 8").TextFrame.TextRange.Text="Value of Surname"


To something like
 

$oDoc.Shapes("Group 5").GroupItems($TB).TextFrame.TextRange.Text = "Value of Surname"

The reason being I was hoping to have the Text box name/replacements in an array.
Column 0 for the type where it's Text Box 1/2/3/4/5/6, and Column 1 for the Text Box 8/11/14 etc scenario
[1][8][$SchoolName]
[2][11][$TownName]
[3][14][$Forename]
[4][15][$Surname]
[5][16][$Desk]
[6][61][$ID number}

Then I could have a single for/next to populate both types depending on the case statement above.

 

Hope that makes sense?

I apologise for the repeated questions, but I'm having a mental block working with Office :)
 

Posted

Never mind! I think I've figured it out :)

Now I just have 1 text box which seems to corrupt when it gets replaced.

It has "000000000*" followed by hex characters at the end - 0D-07-0D-07-0D
Which I think is because the Word document is configured to use that as the footer.
If I change the text directly (with or without the hex at the end), it breaks the text box and the footer doesn't change.

If I use $NewVal = StringReplace($CurVal, "000000000*", $IDNumber, it breaks.

 

If I populate CTRL H and use hot keys to trigger a search replace inside Word, it works.
So I'm ALMOST there!!

 

Posted

In case it got lost in my assorted replies...

Thank you very much for the help and assistance provided with my query.

 

I may be back with similar questions about filling in PDF files. Though it looks like I may have to use 3rd party software like pdftk to get that done, so hopefully I'll muddle through!

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
×
×
  • Create New...