Export (0) Print
Expand All

Microsoft Office Code Compatibility Inspector user's guide

Office 2010
 

Applies to: Office 2010

Topic Last Modified: 2012-01-27

The Microsoft Office Code Compatibility Inspector helps you troubleshoot compatibility issues in your Microsoft Visual Basic for Application (VBA) Macros and add-ins.

Use the Microsoft Office Code Compatibility Inspector to inspect VBA code that you created in previous versions of Microsoft Office and to help you make any Windows Application Programming Interface (API) calls in your code compatible with the 64-bit edition of Microsoft Office 2010.

In this article:

The Microsoft Office Code Compatibility Inspector for is designed to help an enterprise or small business update Visual Basic for Applications (VBA) and Visual Studio Tools for Office code so that it is compatible with Office 2010. The Inspector does not correct code; it inspects code, and then comments specific lines of code that reference items in the object model that have been changed or deprecated. (In VBA code, the tool also comments Declare statements for 64-bit compatibility.) You can then modify the code based on the comments, or use the links that are provided in the comments to view topics on the Web that are pertinent to a particular line of your code.

Again, it is up to you to modify the code if you determine that it needs to be modified.

The key features of the Office Code Compatibility Inspector include the following:

  • It consists of four add-ins that load, one add-in per application, in Excel 2010, PowerPoint 2010, Word 2010, and Visual Studio 2008.

  • It runs on a per-user or a per-document basis. For VBA, users open a document and run the tool from the Developer tab. For Visual Studio projects, the developer runs the tool from the Tools menu.

  • It scans the projects in the current document or Visual Studio Solution by using a simple text search, looking for parentObject.Property combinations, and scans Declare statements for 64-bit compatibility (in VBA).

  • It adds comments in the code where it finds other potential issues.

  • It displays a summary and a detailed report of its findings after it completes its inspection.

You cannot use this tool to inspect code from Microsoft Outlook or Microsoft Access. However, you can use the tool to inspect Excel, PowerPoint, and Word code for interaction with the Outlook object model.

To install the Office Code Compatibility Inspector, follow these steps:

  1. Download the Update 1 version of OCCI from Office 2010 Tool: Compatibility Inspector (http://go.microsoft.com/fwlink/p/?LinkId=171093). Save it to your desktop or some other location that is convenient to you, and then browse to the file and open it to start the installation.

    • You can choose to install only the Visual Studio add-in.

    • You can choose to install only the Office add-ins.

    • Or, you can choose to install both.

  2. Follow the prompts and then choose Finish to complete the installation.

For each Office application in which you plan to use the tool, do the following:

  1. Open Excel 2010, PowerPoint 2010, or Word 2010 if it is not already open.

  2. On the File tab, choose Options.

  3. Choose Customize Ribbon.

  4. Under Choose commands from on the left side of the dialog box, choose Popular Commands.

  5. Under Customize the ribbon on the side of the dialog box, choose Main tabs, and then choose the Developer check box.

  6. Choose OK.

For each Office application in which you plan to use the tool, do the following:

  1. Open Excel 2010, PowerPoint 2010, or Word 2010 if it is not already open.

  2. On the File tab, choose Options.

  3. Choose Trust Center.

  4. Choose Trust Center Settings.

  5. On the Macro Settings tab, select Trust access to the VBA project object model.

To inspect a document for compatibility, follow these steps:

  1. Open the document in Excel 2010, PowerPoint 2010, or Word 2010.

  2. On the Developer tab, choose Inspect VBA Code.

    Figure 1. Code Compatibility Inspector options on the Developer tab

    Inspector options on the Developer tab
  3. In the Inspect VBA Project dialog box, select or clear the options as appropriate, and then choose Inspect.

    Figure 2. Inspect VBA Project dialog box

    Inspect VBA Project dialog box
    1. Choose Inspect Visual Basic for Application Projects so you can inspect the VBA project for items in the object model that have changed or have been removed.

    2. Choose Inspect Declare statements if your project will only be run on Office 2010, or your project might run on a system that is running 64-bit Office 2010.

    3. Choose Add comments to place comments in your code where the tool identifies potential compatibility issues. The comments that the Inspector adds look similar to the following example.

      '<VBA_INSPECTOR>
      '      <DEPRECATION>
      '        <MESSAGE>Potentially contains ... </MESSAGE>
      '        <ITEM>AnswerWizard.ResetFileList</ITEM>
      '        <URL>http://go.microsoft.com/fwlink/p/?LinkID=171730</URL>
      '      </DEPRECATION>
      '<VBA_INSPECTOR>
      
      
    4. Choose Detailed Report to create a report at the end of the inspection process. The report is a text file that looks similar to the following example.

      SUMMARY:
      ========
      
      Document scanned:        c:\TestFile.xls
      Date Scanned:            Thursday, November 12, 2009
      Total lines scanned:     101
      Total items found:       1
      Deprecated items:        0
      Changed items:           1
      Redesigned items:        0
      Declare statements:      0
      
      DETAILS:
      ========
      
      MODULE:            Module1
      FUNCTION:          Macro1
      LINE:              19
      TYPE:              CHANGE
      ITEM:              Workbook.VBProject
      URL:               http://go.microsoft.com/fwlink/p/?LinkID=170116
      CODE:              For Each comp In
      ActiveWorkbook.VBProject.VBComponents
      
      
  4. After the Inspector completes its scan, it displays a summary report similar to the following.

    Figure 2a. Code Compatibility Inspector Summary

    Code Compatibility Inspector Summary
    • Total lines scanned – Total number of VBA code lines scanned in the document.

    • Total items found – Total number of problematic items that the Inspector found in the code, including Declare statements to update, changed items, deprecated items, and items affected by design changes.

    • Deprecated items – Items in the code that were removed from the object model, or are no longer supported in it. If your code is dependent on a deprecated item, you must rewrite that portion of the code.

    • Changed items – Items in the code that use a command whose syntax has changed. If your code uses outdated syntax, you must update the code.

    • Redesigned items – Items in the code whose syntax is the same and still exists, but whose updated design might yield unexpected results against your code. For example, formatting a particular text box might have changed because of new text services, and as a result, your code might create a text box, but the layout of the text in the box might be different from previous versions.

    • Declare statements – Total number of Windows API statements detected in the VBA code and then updated for 64-bit compatibility by adding the PTRSAFE keyword.

To inspect a document for compatibility, follow these steps:

  1. Open the solution that you want to inspect in Visual Studio Tools for Office.

  2. On the Tools menu, choose Inspect VSTO Code.

    Figure 3. VSTO Tools menu

    VSTO Tools menu
  3. In the Inspect VSTO Project dialog box, select or clear the options as appropriate, and then choose Inspect.

    Figure 4. Inspect VSTO Project dialog box

    Inspect VSTO Project dialog box
    1. Select Inspect Visual Studio Tools for Office Source (VB.NET and C#) to inspect your Visual Studio Tools for Office project for items in the object model that have been changed or removed.

    2. Choose Add comments to place comments in your code where the tool identifies potential compatibility issues. The comments that the Inspector adds look similar to the following example.

      //<VSTO_INSPECTOR>
      //  <DEPRECATION>
      //      <MESSAGE>Potentially contains removed items...</MESSAGE>
      //      <ITEM>[mso]AnswerWizard.ResetFileList</ITEM>
      //      <URL>http://go.microsoft.com/fwlink/p/?LinkID=171730</URL>
      //  </DEPRECATION>
      //</VSTO_INSPECTOR>
      
      
    3. Choose Detailed Report to create a report at the end of the inspection process. The report is a text file that looks similar to the following example.

      SUMMARY:
      ========
      
      Solution scanned:        ExcelAddIn1
      Date scanned:            Thursday, November 12, 2009
      Total lines scanned:     43
      Total items found:       3
      Deprecated items:        3
      Changed items:           0
      Redesigned items:        0
      
      DETAILS:
      ========
      
      MODULE:      ThisAddIn.cs
      FUNCTION:    ThisAddIn_Startup
      LINE:        17
      TYPE:        DEPRECATION
      APP:         mso
      ITEM:        AnswerWizard
      URL:         http://go.microsoft.com/fwlink/p/?LinkID=171730
      CODE:        xlApp.AnswerWizard.ResetFileList();
      
      MODULE:      ThisAddIn.cs
      FUNCTION:    ThisAddIn_Startup
      LINE:        19
      TYPE:        DEPRECATION
      APP:         xls
      ITEM:        SmartTagRecognizers
      URL:         http://go.microsoft.com/fwlink/p/?LinkID=170614
      CODE:        xlApp.SmartTagRecognizers.Recognize = true;
      
      MODULE:      ThisAddIn.cs
      FUNCTION:    ThisAddIn_Startup
      LINE:        22
      TYPE:        DEPRECATION
      APP:         xls
      ITEM:        SmartTags
      URL:         http://go.microsoft.com/fwlink/p/?LinkID=170617
      CODE:        MessageBox.Show(r.SmartTags.Count.ToString());
      
    4. Choose Backup to back up your project files before inspecting your code.

  4. After the Inspector completes its scan, it displays a summary report similar to the following.

    Figure 5. Code Compatibility Inspector Summary

    Code Compatibility Inspector Summary
    • Total lines scanned – Total number of Visual Basic .NET or C# code lines scanned in the document.

    • Total items found – Total number of problematic items that the Inspector found in the code, including changed items, deprecated items, and items affected by design changes.

    • Deprecated items – Items in the code that were removed from the object model, or are no longer supported in it. If your code is dependent on a deprecated item, you must rewrite that portion of your code.

    • Changed items – Items in the code that use a command whose syntax has changed. If your code uses outdated syntax, you must update the code.

    • Redesigned items – Items in the code whose syntax is the same and still exists, but whose updated design might yield unexpected results against your code. For example, formatting a particular text box might have changed because of new text services, and as a result, your code might create a text box, but the layout of the text in the box might be different from previous versions.

    • Declare statements – Total number of Windows API statements detected in the VBA code and then updated for 64-bit compatibility by adding the PTRSAFE keyword.

If the Inspector finds Changed, Deprecated, or Redesigned items in your code, you must debug your code and resolve any issues. We recommend that you perform a full test pass on your code, inspecting each function. As you debug your code, check for Office Code Compatibility Inspector comments above the lines that break your code. Those comments should help you to determine the underlying problem with that particular line of code. If the problem is not immediately obvious to you, paste the URL that is in the comments into your browser to get more information.

To remove the comments from the code after you complete the process and verify your code for Office 2010 compatibility, choose Remove Comments on the Developer tab in your Office 2010 application.

The Inspector removes all comments that it placed in your VBA project and then notifies you how many items it removed.

Figure 6. Message that specifies the number of items removed

Message that specifies the number of items removed

To remove the comments from the code after you complete the process and verify your code for Office 2010 compatibility, choose Remove VSTO Inspector Comments on the Tools menu in Visual Studio.

The Inspector removes all comments that it placed in your Visual Studio Tools for Office project and then notifies you how many items it removed.

Figure 6a. Message that specifies the number of items removed

Message that specifies the number of items removed

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft