Microsoft KB Archive/142145

= Microsoft Knowledge Base =

XL: Example Macro to Set Workbook Summary Info
Last reviewed: June 12, 1997

Article ID: Q142145

The information in this article applies to:


 * Microsoft Excel for Windows, versions 5.0 and 5.0c
 * Microsoft Excel for Windows 95, version 7.0
 * Microsoft Excel 97 for Windows
 * Microsoft Excel for NT, version 5.0
 * Microsoft Excel for the Macintosh, versions 5.0, 5.0a
 * Microsoft Excel for the Power Macintosh, versions 5.0, 5.0a

SUMMARY
In Microsoft Excel, you can automatically set the summary properties of a workbook by running a Visual Basic for Applications macro. The macro will alter the information that appears in the Summary Info window (Microsoft Excel versions 5.x) or the Summary tab of the Properties dialog box (Microsoft Excel for Windows 95, version 7.0, and Microsoft Excel 97).

The first sample macro in this article sets the following summary items:

Title Subject Author Keywords Comments If you are running Microsoft Excel for Windows 95, version 7.0, or Microsoft Excel 97, use the second macro to update these items as well:

Category Manager Company

MORE INFORMATION
Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

To run the sample macros included in this article
  In a new workbook, point to Macro on the Insert menu, and then click Module. In Microsoft Excel 97, click the Tools menu, point to Macro, and click Visual Basic Editor. Then, click Module on the Insert menu.   In the inserted module, enter the following sample macros: 'This macro prompts the user for information 'about the document and enters that information 'in the Summary tab of the Properties dialog box '(or in the Summary Info Window in 5.0).

Sub SetSummaryProperties1

'Dimension the variables for the field entries Dim wb_title As String, wb_subject As String Dim wb_author As String, wb_keywords As String Dim wb_comments As String

'Prompt the user for the information to be entered on     'the summary page wb_title = InputBox("Enter a Summary title:") wb_subject = InputBox("Enter a subject:") wb_author = InputBox("Enter the author's name:") wb_keywords = InputBox("Enter some keywords" & _                          " for this document:") wb_comments = InputBox("Enter any comments about the document:")

'Update the Summary tab with the information 'that was gathered in the input boxes With ActiveWorkbook .Title = wb_title .Subject = wb_subject .Author = wb_author .Keywords = wb_keywords .Comments = wb_comments End With

End Sub

'This macro prompts the user for more information 'about the document and enters that information 'in the Summary tab of the Properties dialog box.

Sub SetSummaryProperites2

'Dimension variables Dim wb_manager As String, wb_company As String Dim wb_category As String

'Prompt the user for summary information wb_manager = InputBox("Enter the name of your manager:") wb_company = InputBox("Enter your company name:") wb_category = InputBox("Enter a category for this workbook:")

'Update the Summary tab with the information 'that was gathered in the input boxes.

With ActiveWorkbook .BuiltinDocumentProperties("Manager") = wb_manager .BuiltinDocumentProperties("Company") = wb_company .BuiltinDocumentProperties("Category") = wb_category End With

End Sub  To run the macros, click Macro on the Tools menu. (In Microsoft Excel 97, click the Tools menu, point to Macro, and click Macros.) Select the SetSummaryProperties1 macro or the SetSummaryProperties2 macro, and click Run.

To view the updated items, use the appropriate procedure for your version of Microsoft Excel:


 * If you are using Microsoft Excel version 5.0, click Summary Info on the File menu.
 * If you are using Microsoft Excel for Windows 95, version 7.0, or Microsoft Excel 97, click Properties on the File menu, and then click the Summary tab.