XL5: Macro to Find Directory in WIN.INI for an ApplicationLast reviewed: September 2, 1997Article ID: Q110692 |
The information in this article applies to:
SUMMARYIn Microsoft Excel 5.0 for Windows, you can create a macro to find the default directory of any application that registers itself in the [EXTENSIONS] section of the WIN.INI file. Given the three-character extension for the application’s file, the macro below uses the Microsoft Windows dynamic-link libraries (DLLs) to return the default directory information.
MORE INFORMATIONMicrosoft 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. NOTE: It may be possible to work around this situation by creating a macro that makes calls to the Windows application programming interface (API). This type of programming is supported by the Windows Software Development Kit (SDK) and the Visual Basic, Professional Edition, support groups. The level of support you can receive from these groups depends on the individual support policies of the group. (Microsoft support engineers may not be able to assist in specific construction of macros that use API programming.) 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.
Sample Macro CodeOption Explicit
'Enter the following declare statement needs as a single line. Declare Function GetProfileString Lib "KERNEL" (ByVal lpAppName As _ String, ByVal lpKeyName As String, ByVal lpDefault As String, _ ByVal lpReturnedString As String, ByVal nSize As Integer) As Integer Sub Application_Directory() Dim Path As String * 255, Ext As String, Directory As String Dim Back_Slash As Integer, Length As Integer Ext = InputBox("Enter the 3 letter extension of the application.") 'If Cancel was chosen then end procedure If Len(Ext) = 0 Then Exit Sub 'Gets information from the WIN.INI file and stores in the "path" 'variable Length = GetProfileString("Extensions", Ext, "", Path, Len(Path)) 'Tests for no application found If InStr(Path, "\") = 0 Then MsgBox "Application not found." Else Back_Slash = 255 While Mid(Path, Back_Slash, 1) <> "\" Back_Slash = Back_Slash - 1 Wend Directory = Left(Path, Back_Slash - 1) MsgBox "The directory of the application which uses the " & _ "extension '" & Ext & "' is " & Directory & "." End If End SubTo run this macro, place the insertion point anywhere in the Sub Application_Directory() line and either press F5 or choose Start from the Run menu. When you are prompted to enter a three-letter extension, enter an extension and choose OK. The macro will use the Microsoft Windows API to determine which directory contains the application that uses that three-letter extension. For example, if you enter "xls" (without the quotation marks), the message box will tell you where the Microsoft Excel application is installed.
MORE INFORMATIONFor information about creating a similar Visual Basic macro to find the default printer and port assignments, query on the following words in the Microsoft Knowledge Base:
device and port and visual and basic and printer REFERENCESMicrosoft Windows SDK Microsoft Visual Basic 3.0 Professional - WINAPI31.HLP help file
|
Additional query words: 5.00 5.0 call register
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |