Accessing Word objects with a varaible object name

snowblizz

Well-known Member
Joined
Mar 16, 2009
Messages
1,123
Working with some stuff in Word 2010 and the VBA seems a wee bit different than what I'm used to in Excel.

I'm trying to access a bunch of objects to change the width/height.
There's around a thousand of them. Radio buttons copied from a web survey. I want them a bit smaller to make it all compacter in the Word document. They don't need to work, I just need to recreate the survey visually for an appendix.

The following two examples allows me to change the properties for DefaultOcxName995 and DefaultOcxName5 respectively.

Code:
ThisDocument.DefaultOcxName995.Width = 11.7
ThisDocument.DefaultOcxName995.Height = 11.7

ThisDocument.DefaultOcxName5.Width = 11.7
ThisDocument.DefaultOcxName5.Height = 11.7

But how could I access them with a variable object name? Like I said there's something like a thousand of them.
They seem to belong to the ThisDocument.InLineshapes (the .Count matches) and I thought would be accessible with ThisDocument.InLineshapes(index) but that does not seem to work.
Trying to do a loop to run through them all but I can't get either a "for each" or "for x to y" loop working because I can't seem to be able to access them in any way.
Not sure if it matters but they are nested inside tables in the word doc (for layout reasons).

I was looking at this in Word 2003 (at home) as well, and here they are simply images, if anyone knows how I could access it that way instead.
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Do you know how the checkboxes were created?
 
Upvote 0
Well originally they are HTML from a web survey, I copied the page from the web browser and pasted into Word basically. The boxes are HTML <input> tags.
If that helps any?
 
Upvote 0
Edit, some more info that fell afoul of the 10 min grace period.

The properties box lists it as "DefaultOcxName HTMLOption"
Since I did gone and break something in the file I went back and saved it as HTML page and opened it up that way in Word, and has the same properties as what I was looking at earlier. Namely the following

Appearance - checked true/false
Misc - (Name) DefaultOcxName1105
- Height 18,4
- HTMLName rt_297857_3
- Value 2
-Width 20,1

The following reacts
If ThisDocument.InlineShapes(99).Height = 18.4 Then
Debug.Print ThisDocument.InlineShapes(99).Width

But not this:
Sub test()
For x = 98 To x = 99
If ThisDocument.InlineShapes(x).Height = 18.4 Then
Debug.Print ThisDocument.InlineShapes(x).Width
End If

Next
End Sub


End If
 
Last edited:
Upvote 0
Can you attach a document to a post with some representative checkboxes & data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab.
 
Upvote 0
Can you attach a document to a post with some representative checkboxes & data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab.

I could, but I don't think it's worth anyone's time anymore. I popped in to mention this right now actually.
I broke down after staring at this issue for a while and brute-forced it. Or in other words did it manually, after a couple of hours I managed to get really fast at fixing it. For some reason Word2010 became devilishly unstable so I re-did quite a few sections. With a little bit of copy-pasting and I guess some voodoo (I "downgraded" the file to Word2003 compatible) the option buttons were reduced to pictures that pasted into Excel where I can write macros to resizes them easily and found I could just paste over the table cells in Word mostly eliminating the need to change each and every one manually.

Thanks for looking at this guys/gals anyway. If anyone wants to try and figure out what the erk was going on just for the hell of it I am more than happy to provide "real data". A lot of you have seen it anyway so it's not a secret.:stickouttounge: But for now the problem is essentially "solved".
 
Upvote 0

Forum statistics

Threads
1,225,665
Messages
6,186,312
Members
453,349
Latest member
neam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top