How to grey out a macro in PowerPoint 2000 when invalid???

M

MMC Monster

Hi.
I've created a small macro that adds a different way to insert symbols
at the current cursor position in a Power Point 2000 presentation.
My problem (right now, at least. ) is that if I run my macro and there's
no cursor, the macro crashes, saying:
Run-time error '-2147188160 (80048240)':
Selection (unknown member): Invalid request. Nothing appropriate is
currently selected.

The function I use to add text is:
Set InsertedText = _
ActiveWindow.Selection.TextRange.InsertSymbol( _
FontName:="Symbol", CharNumber:=Str(31 + 5 * 28 + 5), _
Unicode:=msoFalse)

My question: Is it possible to have the menu item for my macro be
greyed-out when there's no valid current cursor position?

Following is what I currently have in my Auto_Open and Auto_Close functions.

Thanks for any help.



Sub Auto_Open()

Dim NewControl As CommandBarControl

' Store an object reference to a command bar.
Dim ToolsMenu As CommandBars

' Figure out where to place the menu choice.
Set ToolsMenu = Application.CommandBars

' Create the menu choice. The choice is created in the first
' position in the Tools menu.
Set NewControl = ToolsMenu("Insert").Controls.Add _
(Type:=msoControlButton, _
Before:=5)

' Name the command.
NewControl.Caption = "Insert S&ymbol Macro"

' Connect the menu choice to your macro. The OnAction property
' should be set to the name of your macro.
NewControl.OnAction = "PowerPoint2000InsertSymbol"

End Sub

Sub Auto_Close()

Dim oControl As CommandBarControl
Dim ToolsMenu As CommandBars

' Get an object reference to a command bar.
Set ToolsMenu = Application.CommandBars

' Loop through the commands on the tools menu.
For Each oControl In ToolsMenu("Insert").Controls

' Check to see whether the comand exists.
If oControl.Caption = "Insert S&ymbol Macro" Then

' Check to see whether action setting is set to ChangeView.
If oControl.OnAction = "PowerPoint2000InsertSymbol" Then

' Remove the command from the menu.
oControl.Delete
End If
End If
Next oControl

End Sub
 
S

Shyam Pillai

Forgot to mention that you need to create an event trap and trap selection events to disable the state of the menu button

You can find examples to create an event trap in the programming section of the PowerPoint FAQ www.pptfaq.co

Regard
Shyam Pilla

http://www.mvps.org/skp/index.htm

----- MMC Monster wrote: ----

Hi
I've created a small macro that adds a different way to insert symbols
at the current cursor position in a Power Point 2000 presentation
My problem (right now, at least. ) is that if I run my macro and there's
no cursor, the macro crashes, saying
Run-time error '-2147188160 (80048240)'
Selection (unknown member): Invalid request. Nothing appropriate is
currently selected

The function I use to add text is
Set InsertedText =
ActiveWindow.Selection.TextRange.InsertSymbol(
FontName:="Symbol", CharNumber:=Str(31 + 5 * 28 + 5),
Unicode:=msoFalse

My question: Is it possible to have the menu item for my macro be
greyed-out when there's no valid current cursor position

Following is what I currently have in my Auto_Open and Auto_Close functions

Thanks for any help



Sub Auto_Open(

Dim NewControl As CommandBarContro

' Store an object reference to a command bar
Dim ToolsMenu As CommandBar

' Figure out where to place the menu choice
Set ToolsMenu = Application.CommandBar

' Create the menu choice. The choice is created in the firs
' position in the Tools menu
Set NewControl = ToolsMenu("Insert").Controls.Add
(Type:=msoControlButton,
Before:=5

' Name the command
NewControl.Caption = "Insert S&ymbol Macro

' Connect the menu choice to your macro. The OnAction propert
' should be set to the name of your macro
NewControl.OnAction = "PowerPoint2000InsertSymbol

End Su

Sub Auto_Close(

Dim oControl As CommandBarContro
Dim ToolsMenu As CommandBar

' Get an object reference to a command bar
Set ToolsMenu = Application.CommandBar

' Loop through the commands on the tools menu
For Each oControl In ToolsMenu("Insert").Control

' Check to see whether the comand exists
If oControl.Caption = "Insert S&ymbol Macro" The

' Check to see whether action setting is set to ChangeView
If oControl.OnAction = "PowerPoint2000InsertSymbol" The

' Remove the command from the menu
oControl.Delet
End I
End I
Next oContro

End Su
 
S

Shyam Pillai

You should check for the selection type and perform the insertion when it satisfies the criteria for text to be inserted

Regard
Shyam Pilla

http://www.mvps.org/skp/index.htm

----- MMC Monster wrote: ----

Hi
I've created a small macro that adds a different way to insert symbols
at the current cursor position in a Power Point 2000 presentation
My problem (right now, at least. ) is that if I run my macro and there's
no cursor, the macro crashes, saying
Run-time error '-2147188160 (80048240)'
Selection (unknown member): Invalid request. Nothing appropriate is
currently selected

The function I use to add text is
Set InsertedText =
ActiveWindow.Selection.TextRange.InsertSymbol(
FontName:="Symbol", CharNumber:=Str(31 + 5 * 28 + 5),
Unicode:=msoFalse

My question: Is it possible to have the menu item for my macro be
greyed-out when there's no valid current cursor position

Following is what I currently have in my Auto_Open and Auto_Close functions

Thanks for any help



Sub Auto_Open(

Dim NewControl As CommandBarContro

' Store an object reference to a command bar
Dim ToolsMenu As CommandBar

' Figure out where to place the menu choice
Set ToolsMenu = Application.CommandBar

' Create the menu choice. The choice is created in the firs
' position in the Tools menu
Set NewControl = ToolsMenu("Insert").Controls.Add
(Type:=msoControlButton,
Before:=5

' Name the command
NewControl.Caption = "Insert S&ymbol Macro

' Connect the menu choice to your macro. The OnAction propert
' should be set to the name of your macro
NewControl.OnAction = "PowerPoint2000InsertSymbol

End Su

Sub Auto_Close(

Dim oControl As CommandBarContro
Dim ToolsMenu As CommandBar

' Get an object reference to a command bar
Set ToolsMenu = Application.CommandBar

' Loop through the commands on the tools menu
For Each oControl In ToolsMenu("Insert").Control

' Check to see whether the comand exists
If oControl.Caption = "Insert S&ymbol Macro" The

' Check to see whether action setting is set to ChangeView
If oControl.OnAction = "PowerPoint2000InsertSymbol" The

' Remove the command from the menu
oControl.Delet
End I
End I
Next oContro

End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top