Variable as Object

squeebles

New Member
Joined
Feb 13, 2006
Messages
11
i have some labels in a word document that i can manipulate from excel but i want to be able to change each label with one sub. the naming of my labels is in the form of "Label5y" and "Label5n". this sub is meant to determine the contents of a cell and change the labels accordingly. this sub works if i hard code the name of each label but i need them to change dynamically. if there is a different way to go about this i am all ears.

Sub yesNo(col As String, ynLabel As String, i)

Dim labely As String
Dim labeln As String

labely = "Label" & ynLabel & "y"
labeln = "Label" & ynLabel & "n"

If Range(col & i) = "yes" Then
appWD.ActiveDocument.labely.Caption = "(Yes)"
appWD.ActiveDocument.labeln.Caption = "No"
appWD.ActiveDocument.labeln.Font.Strikethrough = True
Else
appWD.ActiveDocument.labely.Caption = "Yes"
appWD.ActiveDocument.labely.Font.Strikethrough = True
appWD.ActiveDocument.labeln.Caption = "(No)"
End If

End Sub
 
hahdawg

Unfortunately OLEObjects doesn't appear to exist in Word.

The only ways I found were InlineShapes and Fields, but as I said neither allows you to use the name.

I'm sure there's something I'm missing though which is why I'm still looking.

Well, that stinks. Maybe create a custom class of InlineShapes in Word and add the Name property to it?
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
i think i need to clarify the problem here.
Code:
appWD.ActiveDocument.Label5y.Caption = "(Yes)"

this works because the label's name is "Label5y" but when i try to concatenate variables that produce the same name it does not work.
 
Upvote 0
It's perfectly clear what the problem is.

The problem with finding a solution is that there doesn't appear to be a straightforward method to refer to an ActiveX on a Word document using it's name.

I can post code that will loop through all the ActiveX controls on the forms and looks for a label with a particular name, but you would need to repeat that for each label.
 
Upvote 0

Forum statistics

Threads
1,215,014
Messages
6,122,697
Members
449,092
Latest member
snoom82

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