How to Find the Path of a Program Using WordBasic

Last reviewed: August 5, 1997
Article ID: Q120772
The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a

SUMMARY

This article describes how you can use a WordBasic macro to return the path of a program that is currently running.

MORE INFORMATION

The following macro example identifies the path for Microsoft Excel. You can substitute any valid Windows executable filename, such as WINWORD, MSACCESS, or POWERPNT in place of EXCEL in the following example.

Declare Function GetModuleFileName Lib "Kernel"(hModule As Integer,
lpFilename As String, nSize As Integer) As Integer

Declare Function GetModuleHandle Lib "Kernel"(lpModuleName As String)
As Integer

Sub MAIN
hModule = GetModuleHandle("EXCEL.EXE") Length = GetModuleFileName(hModule, Buffer$, 255) MsgBox "Path and Filename: " + Buffer$
End Sub

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

REFERENCES

"Microsoft Windows Software Development Kit"

Kbcategory: kbusage kbmacro kbhowto KBSubcategory:


Additional reference words: winword2 winword 6.0a 6.0, 6.0a SDK
word6

Version : 2.0 2.0a 2.0a-CD 2.0b 2.0c
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 5, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.