Microsoft KB Archive/173707

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 10:06, 21 July 2020 by X010 (talk | contribs) (Text replacement - """ to """)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Article ID: 173707

Article Last Modified on 3/29/2007



APPLIES TO

  • Microsoft Word 97 Standard Edition
  • Microsoft PowerPoint 97 Standard Edition
  • Microsoft Excel 97 Standard Edition



This article was previously published under Q173707

For a Microsoft Office XP version of this article, see 290140.
For a Microsoft Office 2000 version of this article, see 212536.
For a Microsoft Office 2001 for Mac version of this article, see 274703.
For a Microsoft Office 98 Macintosh Edition version of this article, see 181058.


SUMMARY

The Microsoft Knowledge Base contains a number of articles that contain sample code for Visual Basic for Applications macros. Many of these macros illustrate basic concepts of programming in Visual Basic for Microsoft Office. This article contains instructions on how to use the sample code to create a new macro, and how to run that macro.

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 a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

Microsoft Excel stores macros in workbooks; Microsoft PowerPoint stores macros in presentations, and Microsoft Word stores macros in templates and documents. To use the sample code in a Knowledge Base article, you must add a new Visual Basic macro (or select an existing macro) in an Excel workbook, PowerPoint presentation or Word template or document. You can then paste or type the sample code into this macro. Use any of the following methods.

To Create a New Macro

  1. Open or create an Excel workbook, PowerPoint presentation or Word template or document as appropriate.
  2. On the Tools menu, point to Macro, and then click Macros.
  3. In the Macros In list, click the Excel workbook, PowerPoint presentation or Word template or document where you want to save the macro.
  4. In the Macro Name box, type a name for the macro.
  5. Click Create to open the Visual Basic Editor.
  6. Type the macro code.

NOTE: Type the macro code between the first line

      Sub <macro name>()
                

and the last line:

      End Sub
                

To add the sample code to the macro using the Clipboard, follow these steps:

  1. Switch to the program that you are using to view the Knowledge Base article, such as Microsoft Internet Explorer.
  2. Select only the sample code between the first line, "Sub <macro name>()" and the last line, "End Sub."
  3. On the Edit menu, click Copy.
  4. Switch to the Visual Basic Editor.
  5. In the Visual Basic Editor, click to place the insertion point between the first line, "Sub <macro name>()" and the last line, "End Sub" of your macro.
  6. On the Edit menu, click Paste.

To Add the Sample Code to a Module

To add code to a module, you must either have an existing module or create a new module. To do this, follow these steps:

  1. Open or create an Excel workbook, PowerPoint presentation or Word template or document as appropriate.
  2. On the Tools menu, point to Macro and then click Visual Basic Editor.
  3. In the Project window of the Visual Basic Editor (by default this is in the upper left corner), click the project icon with the same name as your workbook, presentation, template, or document. If you haven't yet saved your workbook, presentation, template or document, the project name is based on the program that you are using.

          Program                Default project name
          -------------------------------------------
    
          Microsoft Excel        VBAProject(Book1)
    
          Microsoft PowerPoint   VBAProject(Presentation1)
    
          Microsoft Word         Project(Document1)
                                 -or-
                                 TemplateProject(Template1)

    NOTE: If you want to store your macro in the default Microsoft Word template, Normal.dot, double-click the Normal project.

  4. If the project you clicked does not contain a folder called Modules underneath it, click Module on the Insert menu.
  5. Click anywhere in the code window of the module you want to create. The code window is usually in the upper right corner of the Visual Basic Editor.
  6. Type the sample code exactly as it appears in the Knowledge Base article, including the "Sub <macro name>()" and "End Sub" lines. Use the TAB key to indent text.

    NOTE: Lines that begin with an apostrophe (') are comments and are not required to run the macro. However, you may want to type them in to make it easier to understand the macro.

To Run the Macro

  1. Switch from the Visual Basic Editor to Excel, PowerPoint or Word as appropriate.
  2. On the Tools menu, point to Macro and then click Macros.
  3. Click the name of the macro on the Macro Name list and then click Run.


REFERENCES

Microsoft Help for each Office program contains numerous topics about working with macros. Visual Basic help contains extensive information about writing your own code.

For additional information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

163435 VBA: Programming Resources for Visual Basic for Applications



Additional query words: wordcon 8.0 8.00 ppt8 vba vbe visual basic XL97

Keywords: kbfaq kbhowto kbinfo kbmacro kbprogramming KB173707