|
-
Jan 24th, 2011, 10:53 AM
#1
Thread Starter
New Member
use control in word by name
Hi,
I am trying to assign some values to some activex textboxes in a word 2007 document.
i have named the textboxes like txt1,txt2,txt3,txt4,...
Now i m wondering if there is something like this possible:
for i = 1 to 4
getControlByName("txt" & i).text = "test " & i
next
Thanks in advance
-
Jan 24th, 2011, 10:56 AM
#2
Addicted Member
Re: use control in word by name
You might have to go the route of:
Code:
For i - 1 to 4
tmpVal = "txt" & i
getControlByName(tmpVal).text = "test" & i
Next i
-
Jan 24th, 2011, 11:04 AM
#3
Thread Starter
New Member
Re: use control in word by name
Hi fizii,
Thanks for the quick reply.
I 've been trying that already and i know it works fine in .NET but in office VBA it gives me "Sub or Function not defined".
So i was wondering if there is an alternative for this?
-
Jan 25th, 2011, 03:28 AM
#4
Re: use control in word by name
you can try like
vb Code:
For i = 1 To 3 activedocument.Shapes("Text box " & i).TextFrame.TextRange = "test " & i Next
assuming your textboxes are named as default
text box 1
text box 2
etc
or with your existing texboxes
activedocument.Shapes("txt" & i).TextFrame.TextRange = "test " & i
and change to whatever document object you want to use
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|