PPT: Sample VB Code to Manipulate Command Bars

ID: Q161621


The information in this article applies to:
  • Microsoft PowerPoint 98 Macintosh Edition
  • Microsoft PowerPoint 97 For Windows


SUMMARY

This article contains a sample Microsoft Visual Basic for Applications macro (Sub procedure) that enables the Standard, Formatting, or Drawing command bars if they are not visible.


MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft Support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

Sample Visual Basic Procedure


    Type CommandBarType

      NameOfCommandBar As String
      IsVisible As Boolean
      Value As Byte

   End Type

   Sub MakeBarVisible()

      ' Holds command bar information. This is a user-defined datatype
      ' defined in the Declarations section.
      Dim UsedBarList() As CommandBarType

      ' Stores the prompt in the message box.
      Dim message As String

      ' Controls For loop.
      Dim i As Byte

      ' Counts the visible command bars.
      Dim CountVisible As Byte

      ' Stores the return value of the message box.
      Dim result As Integer

      ' Initialize CountVisible.
      CountVisible = 0

      ' Get space in the array for the standard command bar.
      ReDim Preserve UsedBarList(0)

      ' Store the settings for the standard command bar.
      With UsedBarList(0)
         .IsVisible = Application.CommandBars(3).Visible
         .NameOfCommandBar = Application.CommandBars(3).Name
         .Value = 3
      End With

      ' Get space in the array for the Formatting command bar.
      ReDim Preserve UsedBarList(1)

      ' Store the settings for the Formatting command bar.
      With UsedBarList(1)
         .IsVisible = Application.CommandBars(4).Visible
         .NameOfCommandBar = Application.CommandBars(4).Name
         .Value = 4
      End With

      ' Get space in the array for the drawing command bar.
      ReDim Preserve UsedBarList(2)

      ' Store the settings for the Drawing command bar.
      With UsedBarList(2)
         .IsVisible = Application.CommandBars(8).Visible
         .NameOfCommandBar = Application.CommandBars(8).Name
         .Value = 8
      End With

      ' Build the prompt for the message box.
      message = "Would you like me to turn ON the following"
      message = message & " command bar(s)?" & Chr(13)

      ' Loop through the three command bars and see whether visible.
      For i = 0 To 2

         ' See whether the command bar is not visible.
         If UsedBarList(i).IsVisible = False Then
            ' Add a space and a tab and the name of command bar.
            message = message & Chr(13) & Chr(9)
            message = message & UsedBarList(i).NameOfCommandBar
            CountVisible = CountVisible + 1
         End If

      Next i

      ' See whether the three command bars are visible.
      If CountVisible = 0 Then
         ' The three command bars are visible.
         MsgBox "The Standard, Formatting, and Drawing command " _
            & " bars are already visible. Disable one or more and run " _
            & "the macro again.", vbInformation
         End
      End If

      ' Display the message box.
      result = MsgBox(message, vbQuestion + vbYesNo)

      ' Check which button was selected in the message box.
      If result = vbNo Then
         End
      End If

      ' Turn on the command bars.
      For i = 0 To 2

         ' See whether the command bar is not visible.
         If UsedBarList(i).IsVisible = False Then
            ' Make the command bar visible.
            With Application.CommandBars(UsedBarList(i).Value)
               .Visible = True
            End With
         End If

      Next i

   End Sub 


REFERENCES

For more information about creating Visual Basic for Applications macros, click the Office Assistant in Microsoft PowerPoint, type how to create a macro, click Search, and then click to view "Create a macro in Visual Basic Editor."

For more information about running Visual Basic for Applications macros, click the Office Assistant in Microsoft PowerPoint, type how to run a macro, click Search, and then click to view "Run a macro."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If the Assistant is not able to answer your query, please see the following article in the Microsoft Knowledge Base:

Q176476 OFF: Office Assistant Not Answering Visual Basic Questions
For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:
Q163435 VBA: Programming Resources for Visual Basic for Applications

Additional query words: 97 8.00 kbmacro ppt8 vba vbe commandbar macppt mac_ppt ppt98 98 powerpt toolbar tool bars bar menus menu office

Keywords : kbcode kbmacro kbprg kbdta kbdtacode kbpptvba
Version : MACINTOSH:; WINDOWS:
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


Last Reviewed: November 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.