Hi all,
I would like to add a line to my VBA code to disable a command button called
"Delete Person". I'm not sure how to refer to the button though. The
following attempt didn't work:

ActiveDocument.Range.CommandButton("Delete Person").Enabled = False

I'm using Word 2003.

Many thanks
Tendresse

Re: Disable Command Button by Greg

Greg
Mon Sep 17 06:35:16 CDT 2007

Note while your caption might read Delete Person. That is not a valid name
for a document control.



If you already know the index number of the control you can use a single
line:

Sub Scratchmacro

ActiveDocument.InlineShapes(1).OLEFormat.Object.Enabled = False

End Sub



If there are multiple controls or other inlineshapes then you will need
something like this:



Sub Scratchmacro

ActiveDocument.InlineShapes(GetIndex).OLEFormat.Object.Enabled = False

End Sub



Function GetIndex() As Long

Dim i As Long

Dim oILS As InlineShape

For Each oILS In ActiveDocument.Range.InlineShapes

i = i + 1

If oILS.Type = wdInlineShapeOLEControlObject Then

If InStr(oILS.OLEFormat.Object.Name, "CommandButton1") > 0 Then

Exit For

End If

End If

Next oILS

GetIndex = i

End Function


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

"Tendresse" <Tendresse@discussions.microsoft.com> wrote in message
news:BBFB08CF-6CC0-4203-BCDD-51B8AD5F32A6@microsoft.com...
> Hi all,
> I would like to add a line to my VBA code to disable a command button
> called
> "Delete Person". I'm not sure how to refer to the button though. The
> following attempt didn't work:
>
> ActiveDocument.Range.CommandButton("Delete Person").Enabled = False
>
> I'm using Word 2003.
>
> Many thanks
> Tendresse



Re: Disable Command Button by Tendresse

Tendresse
Mon Sep 17 19:28:01 CDT 2007

Thanks for your help, Greg. Much appreciated.

"Greg Maxey" wrote:

> Note while your caption might read Delete Person. That is not a valid name
> for a document control.
>
>
>
> If you already know the index number of the control you can use a single
> line:
>
> Sub Scratchmacro
>
> ActiveDocument.InlineShapes(1).OLEFormat.Object.Enabled = False
>
> End Sub
>
>
>
> If there are multiple controls or other inlineshapes then you will need
> something like this:
>
>
>
> Sub Scratchmacro
>
> ActiveDocument.InlineShapes(GetIndex).OLEFormat.Object.Enabled = False
>
> End Sub
>
>
>
> Function GetIndex() As Long
>
> Dim i As Long
>
> Dim oILS As InlineShape
>
> For Each oILS In ActiveDocument.Range.InlineShapes
>
> i = i + 1
>
> If oILS.Type = wdInlineShapeOLEControlObject Then
>
> If InStr(oILS.OLEFormat.Object.Name, "CommandButton1") > 0 Then
>
> Exit For
>
> End If
>
> End If
>
> Next oILS
>
> GetIndex = i
>
> End Function
>
>
> --
> Greg Maxey/Word MVP
> See:
> http://gregmaxey.mvps.org/word_tips.htm
> For some helpful tips using Word.
>
> "Tendresse" <Tendresse@discussions.microsoft.com> wrote in message
> news:BBFB08CF-6CC0-4203-BCDD-51B8AD5F32A6@microsoft.com...
> > Hi all,
> > I would like to add a line to my VBA code to disable a command button
> > called
> > "Delete Person". I'm not sure how to refer to the button though. The
> > following attempt didn't work:
> >
> > ActiveDocument.Range.CommandButton("Delete Person").Enabled = False
> >
> > I'm using Word 2003.
> >
> > Many thanks
> > Tendresse
>
>
>

Re: Disable Command Button by fumei

fumei
Tue Sep 25 12:13:59 CDT 2007

Not exactly sure.. is this an ActiveX commandbutton IN the document?

If so, you can action it directly, by name. Say it is CommandButton1 (and
you should actually change your names from the defaults....)

Within the ThisDocument module:

CommandButton1.Enabled = False


Within any standard module:

ThisDocument.CommandButton1.Enabled = False

You do not need the index number.

--
Message posted via http://www.officekb.com