OL98: How to Programmatically Change Outlook's User Interface

ID: Q194884

The information in this article applies to:

SUMMARY

When you are developing a solution with Microsoft Outlook 98, you may want to enable or disable the Outlook toolbars and window panes programmatically. This article illustrates how you can automate this in Outlook.

MORE INFORMATION

The following Microsoft Visual Basic or Visual Basic for Applications subroutine resets Outlook to the default Outlook user interface settings. This environment will persist in Outlook until changed by the user or code.

The State property determines whether the toolbar is visible. If the state of the button is up (msoButtonUp) then the toolbar is not displayed. If the state of the toolbar button is down then the toolbar is visible.

Prior to running this code, be sure to reference the Microsoft Outlook 98 Object Library and the Microsoft Office 8.0 Object Library. Outlook must also be currently running.

   Sub ResetOutlookUserInterface()

      Dim outapp As Outlook.Application
      Dim olns As Outlook.NameSpace
      Dim MyExplorer As Outlook.Explorer
      Dim MyMenu As CommandBar
      Dim MyCmd As CommandBarControl

      Set outapp = New Outlook.Application
      Set olns = outapp.GetNamespace("MAPI")
      Set MyInbox = olns.GetDefaultFolder(olFolderInbox)

      ' Get the active application-level window displayed
      Set MyExplorer = outapp.ActiveExplorer

      ' Reference the View menu
      Set MyMenu = MyExplorer.CommandBars.Item("View")

      ' Display the Outlook Bar
      Set MyCmd = MyMenu.Controls("Outlook Bar")
      If MyCmd.State = msoButtonUp Then MyCmd.Execute

      ' Hide the Folder List
      Set MyCmd = MyMenu.Controls("Folder List")
      If MyCmd.State = msoButtonDown Then MyCmd.Execute

      ' Display the Standard toolbar
      Set MyCmd = MyMenu.Controls("Toolbars").Controls("Standard")
      If MyCmd.State = msoButtonUp Then MyCmd.Execute

      ' Hide the Advanced toolbar
      Set MyCmd = MyMenu.Controls("Toolbars").Controls("Advanced")
      If MyCmd.State = msoButtonDown Then MyCmd.Execute

      ' Hide the Remote toolbar
      Set MyCmd = MyMenu.Controls("Toolbars").Controls("Remote")
      If MyCmd.State = msoButtonDown Then MyCmd.Execute

      ' Hide the preview pane
      Set MyCmd = MyMenu.Controls("Preview Pane")
      If MyCmd.State = msoButtonDown Then MyCmd.Execute

      ' Display the status bar
      Set MyCmd = MyMenu.Controls("Status Bar")
      If MyCmd.State = msoButtonUp Then MyCmd.Execute

      Set MyCmd = Nothing
      Set MyMenu = Nothing
      Set MyExplorer = Nothing
      Set olns = Nothing
      Set outapp = Nothing

   End Sub

REFERENCES

For more information about using programming Command Bars, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q182394
   TITLE     : OL98: How to Use Command Bars in Outlook Solutions

For more information about creating solutions with Microsoft Outlook 98, please see the following articles in the Microsoft Knowledge Base:

   Article-ID: Q180826
   Title     : OL98: Resources for Custom Forms and Programming

   Article-ID: Q182349
   Title     : OL98: Questions About Custom Forms and Outlook Solutions

Additional query words: kbDSupport kbOutlook kbAutomation kbOutlook97 kbOutlook98 kbOutlookObj OutSol OutSol98 vbscript
Keywords          : kbdta OffVBS kbAutomation 
Version           : WINDOWS:
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: May 17, 1999