Microsoft KB Archive/824000

= HOW TO: Determine Office Document and Managed Code Extension Paths at Run Time =

Article ID: 824000

Article Last Modified on 2/3/2006

-

APPLIES TO


 * Microsoft Visual Studio Tools for the Microsoft Office System version 2003
 * Microsoft Office Word 2003
 * Microsoft Office Excel 2003

-



SUMMARY
This article describes how to programmatically determine the path of a Microsoft Office Word document or a Microsoft Office Excel workbook, and the path of the associated Microsoft .NET Framework assembly (managed code extension).



MORE INFORMATION
If you use System.IO.Path.GetFullPath(&quot;.&quot;) from a managed code extension to determine the path of the assembly, you may receive inconsistent results. Because the value of GetFullPath(&quot;.&quot;) depends on the location of the starting process, you might receive different results when you debug the solution in Visual Studio .NET 2003 than you receive at run time. This article describes how to receive consistent path information for both Word documents and Excel Workbooks and their associated assemblies.

Microsoft Office Word
 Create a new Microsoft Office System project:  Start Visual Studio .NET 2003. On the File menu, point to New, and then click Project. Under Project Types, expand Microsoft Office System Projects, and then click Visual Basic Projects. Under Templates, click Word Document. Name the new project PathInformationWD. Click OK.

The Microsoft Office Project Wizard appears. In the Microsoft Office Project Wizard, click Finish. </li>  In the new project, add the following code to the ThisDocument_Open event handler: Dim asm As System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly MsgBox(&quot;The location of the assembly: &quot; & asm.CodeBase & vbCrLf & vbCrLf & _       &quot;The location of the document: &quot; & ThisDocument.Path & &quot;\&quot; & ThisDocument.Name) </li> Press F5 to build and then run the project.</li> When the document opens in Word, a message box appears. Verify the path information for the .NET Framework assembly and the Word document, and then click OK to close the message box.</li> Quit Word.</li> In Windows Explorer, double-click the Word document PathInformationWD.doc to open the document in Word.

Note This step tests the project at run time.</li> Verify that the same path information appears in the message box that appeared when you debugged the project in Visual Studio .NET 2003.</li></ol>

Microsoft Office Excel
 Create a new Microsoft Office System project:  Start Visual Studio .NET 2003.</li> On the File menu, point to New, and then click Project.</li> Under Project Types, expand Microsoft Office System Projects, and then click Visual Basic Projects.</li> Under Templates, click Excel Workbook. Name the new project PathInformationXL. Click OK.

The Microsoft Office Project Wizard appears.</li> In the Microsoft Office Project Wizard, click Finish.</li></ol> </li>  In the new project, add the following code to the ThisWorkbook_Open event handler: Dim asm As System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly MsgBox(&quot;The location of the assembly: &quot; & asm.CodeBase & vbCrLf & vbCrLf & _       &quot;The location of the Workbook: &quot; & ThisWorkbook.Path & &quot;\&quot; & ThisWorkbook.Name) </li> Press F5 to build and then run the project.</li> <li>When the workbook opens in Excel, a message box appears. Verify the path information for the .NET Framework assembly and the Excel workbook, and then click OK to close the message box.</li> <li>Quit Excel.</li> <li>In Windows Explorer, double-click the Excel workbook PathInformationXL.xls to open it in Excel.

Note This step tests the project at run time.</li> <li>Verify that the same path information appears in the message box that appeared when you debugged the project in Visual Studio .NET 2003.</li></ol>

Keywords: kbhowto kbofficeauto kbpia KB824000

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.