Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Thu, 4 Sep 2008 02:40:00 -0700,    group: microsoft.public.word.vba.general        back       


Word 2002/2003 ActiveX Control Name property   
I've added 4 form controls on to a Word 2002 SP3 document 2 Label(s) and 2 
CommandButton(s) and assigned them names.  I have then coded some logic on 
the command button to return the text of label 1 and 2 respectively.

This works fine but when I open the document up in Word 2003 SP3, save it 
and reopen the document in Word 2002 the 'Name' property has been randomly 
transposed to different items so that what use to be called 'label1' is now 
attached to a CommandButton and a CommandButton will have the name 'label2', 
etc.

I have researched as much as possible but have found very little on this 
topic.  One URL 
http://msdn.microsoft.com/en-us/library/aa140269(office.10).aspx says 

'The VBA properties of ActiveX controls are not always stable. For example, 
the Name property, given by Word upon insertion of the control, may change 
unexpectedly. Again, later versions of Word are more stable than earlier 
ones, especially Word 97. '

If this is the case how can I uniquely identify the controls on my document 
if I can't rely on the 'Name' field being immutable?
date: Thu, 4 Sep 2008 02:40:00 -0700   author:   Hobs

RE: Word 2002/2003 ActiveX Control Name property   
"Hobs" wrote:

> I've added 4 form controls on to a Word 2002 SP3 document 2 Label(s) and 2 
> CommandButton(s) and assigned them names.  I have then coded some logic on 
> the command button to return the text of label 1 and 2 respectively.
> 
> This works fine but when I open the document up in Word 2003 SP3, save it 
> and reopen the document in Word 2002 the 'Name' property has been randomly 
> transposed to different items so that what use to be called 'label1' is now 
> attached to a CommandButton and a CommandButton will have the name 'label2', 
> etc.
> 
> I have researched as much as possible but have found very little on this 
> topic.  One URL 
> http://msdn.microsoft.com/en-us/library/aa140269(office.10).aspx says 
> 
> 'The VBA properties of ActiveX controls are not always stable. For example, 
> the Name property, given by Word upon insertion of the control, may change 
> unexpectedly. Again, later versions of Word are more stable than earlier 
> ones, especially Word 97. '
> 
> If this is the case how can I uniquely identify the controls on my document 
> if I can't rely on the 'Name' field being immutable?

You can encase them in bookmarks and use the Bookmark(Index).Range to access 
the control within...
date: Thu, 4 Sep 2008 10:34:03 -0700   author:   Jean-Guy Marcil

RE: Word 2002/2003 ActiveX Control Name property   
I've set the bookmark to the entire document by Ctrl-A and then inserting a 
bookmark.  It seems to indicate that the BookMark object is correct because 
the start and end properties show 0 and 201 respectively (the end of the 
document).  Inspecting the Range property of the bookmark I cannot see the 
ActiveX controls, I've looked at the Range interface and nothing seems to 
expose it other than FormFields property but this count is 0.

Can you give me some more guidance on how I would achieve this?

"Jean-Guy Marcil" wrote:

> "Hobs" wrote:
> 
> > I've added 4 form controls on to a Word 2002 SP3 document 2 Label(s) and 2 
> > CommandButton(s) and assigned them names.  I have then coded some logic on 
> > the command button to return the text of label 1 and 2 respectively.
> > 
> > This works fine but when I open the document up in Word 2003 SP3, save it 
> > and reopen the document in Word 2002 the 'Name' property has been randomly 
> > transposed to different items so that what use to be called 'label1' is now 
> > attached to a CommandButton and a CommandButton will have the name 'label2', 
> > etc.
> > 
> > I have researched as much as possible but have found very little on this 
> > topic.  One URL 
> > http://msdn.microsoft.com/en-us/library/aa140269(office.10).aspx says 
> > 
> > 'The VBA properties of ActiveX controls are not always stable. For example, 
> > the Name property, given by Word upon insertion of the control, may change 
> > unexpectedly. Again, later versions of Word are more stable than earlier 
> > ones, especially Word 97. '
> > 
> > If this is the case how can I uniquely identify the controls on my document 
> > if I can't rely on the 'Name' field being immutable?
> 
> You can encase them in bookmarks and use the Bookmark(Index).Range to access 
> the control within...
date: Thu, 4 Sep 2008 19:27:01 -0700   author:   Hobs

RE: Word 2002/2003 ActiveX Control Name property   
Ok so I've realised I should have been using the 'Field' property instead of 
'FormField'.  I can now access and see the ActiveX Control, i.e. Label and 
CommandButton.

However I still have the issue that if my command button randomly changes 
name on save the associated code for the button won't fire because (as far as 
I can see) it requires the code hook to be in the form <name>_Click().  Is 
there another way to wire up the 'onClick' event of a button without this 
dependency?

The other thought I had was to just enumerate the controls on the page and 
set the name on the controls every time the document is open.  This of course 
would be dependent on the order of the items to be fixed, i.e. will it be 
guaranteed that the order of the items in the Field list always be the same?  
And I am presuming it's a left to right, top to bottom sequence.

"Hobs" wrote:

> I've set the bookmark to the entire document by Ctrl-A and then inserting a 
> bookmark.  It seems to indicate that the BookMark object is correct because 
> the start and end properties show 0 and 201 respectively (the end of the 
> document).  Inspecting the Range property of the bookmark I cannot see the 
> ActiveX controls, I've looked at the Range interface and nothing seems to 
> expose it other than FormFields property but this count is 0.
> 
> Can you give me some more guidance on how I would achieve this?
> 
> "Jean-Guy Marcil" wrote:
> 
> > "Hobs" wrote:
> > 
> > > I've added 4 form controls on to a Word 2002 SP3 document 2 Label(s) and 2 
> > > CommandButton(s) and assigned them names.  I have then coded some logic on 
> > > the command button to return the text of label 1 and 2 respectively.
> > > 
> > > This works fine but when I open the document up in Word 2003 SP3, save it 
> > > and reopen the document in Word 2002 the 'Name' property has been randomly 
> > > transposed to different items so that what use to be called 'label1' is now 
> > > attached to a CommandButton and a CommandButton will have the name 'label2', 
> > > etc.
> > > 
> > > I have researched as much as possible but have found very little on this 
> > > topic.  One URL 
> > > http://msdn.microsoft.com/en-us/library/aa140269(office.10).aspx says 
> > > 
> > > 'The VBA properties of ActiveX controls are not always stable. For example, 
> > > the Name property, given by Word upon insertion of the control, may change 
> > > unexpectedly. Again, later versions of Word are more stable than earlier 
> > > ones, especially Word 97. '
> > > 
> > > If this is the case how can I uniquely identify the controls on my document 
> > > if I can't rely on the 'Name' field being immutable?
> > 
> > You can encase them in bookmarks and use the Bookmark(Index).Range to access 
> > the control within...
date: Thu, 4 Sep 2008 21:21:00 -0700   author:   Hobs

RE: Word 2002/2003 ActiveX Control Name property   
"Hobs" wrote:

<snip>

> The other thought I had was to just enumerate the controls on the page and 
> set the name on the controls every time the document is open.  This of course 
> would be dependent on the order of the items to be fixed, i.e. will it be 
> guaranteed that the order of the items in the Field list always be the same?  
> And I am presuming it's a left to right, top to bottom sequence.

If you use that last approach, use individual bookmarks for each ActiveX.
The bookmark name will be the clue as to the name that you should assign to 
the sole ActiveX control within the bookmark range.

Just have your code loop through the bookmark collection.
date: Fri, 5 Sep 2008 09:27:01 -0700   author:   Jean-Guy Marcil

RE: Word 2002/2003 ActiveX Control Name property   
Thanks for the help.  I really needed a way to uniquely and dependably 
reference the ActiveX controls and this certainly does the job.

"Jean-Guy Marcil" wrote:

> "Hobs" wrote:
> 
> <snip>
> 
> > The other thought I had was to just enumerate the controls on the page and 
> > set the name on the controls every time the document is open.  This of course 
> > would be dependent on the order of the items to be fixed, i.e. will it be 
> > guaranteed that the order of the items in the Field list always be the same?  
> > And I am presuming it's a left to right, top to bottom sequence.
> 
> If you use that last approach, use individual bookmarks for each ActiveX.
> The bookmark name will be the clue as to the name that you should assign to 
> the sole ActiveX control within the bookmark range.
> 
> Just have your code loop through the bookmark collection.
>
date: Sun, 7 Sep 2008 07:36:00 -0700   author:   Hobs

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us