M
Marceepoo
I've been trying to figure out how to assign the Title (e.g. "Title$" and the
fulname path (e.g., "Fulname") of the top Word window to variables. I saw
the following text (which I think was) intended for use in a VB script. (It
wouldn't work as a macro "as is" in my Word 2003.)
I wonder if anyone has any tips on how to modify it to make it work in Word
2003 VBA, and where (URL) I could learn about the intersection between vba
and "API" (whatever "API" is). Thanks, Marceepo
Here's the code....
'Win32 API Example: vba Macro to get Active Window Title
'
' THIS text is from page 42 of Scripting for Dragon NaturallySpeaking8 by
Larry V. Allen.
'
'One API function gets the title of the active window. This is needed in
applications
' where commands depend on context. Microsoft has books and web resources
describing
' these API functions in depth. Some functions are dependent upon the
version of Windows.
'declare three Windows functions
Declare Function GetForegroundWindow& Lib "user32" ()
'Declare Function GetWindowTextLengthA& Lib "user32" (ByVal'hwnd&)
Declare Sub GetWindowTextA Lib "user32" _
(ByVal hwnd&, ByVal lpsz$, ByVal cbMax&)
'use Windows functions to obtain a string with the
'title of the current window. The string is returned
'as the value of the ActiveWindowTitle function.
Function ActiveWindowTitle$()
Dim ActiveWindow As Long
Dim TitleLen As Long
Dim Title As String
ActiveWindow = GetForeqroundWindow()
TitleLen = GetWindowTextLengthA(ActiveWindow)
Title$ = Space$(TitleLen)
GetWindowTextA ActiveWindow, Title$, TitleLen + l
ActiveWindowTitle$ = Title$
End Function
'Use the window title -in this case, display it.
'More commonly if would be compared .
Sub Main()
MsgBox ActiveWindowTitle$
End Sub
fulname path (e.g., "Fulname") of the top Word window to variables. I saw
the following text (which I think was) intended for use in a VB script. (It
wouldn't work as a macro "as is" in my Word 2003.)
I wonder if anyone has any tips on how to modify it to make it work in Word
2003 VBA, and where (URL) I could learn about the intersection between vba
and "API" (whatever "API" is). Thanks, Marceepo
Here's the code....
'Win32 API Example: vba Macro to get Active Window Title
'
' THIS text is from page 42 of Scripting for Dragon NaturallySpeaking8 by
Larry V. Allen.
'
'One API function gets the title of the active window. This is needed in
applications
' where commands depend on context. Microsoft has books and web resources
describing
' these API functions in depth. Some functions are dependent upon the
version of Windows.
'declare three Windows functions
Declare Function GetForegroundWindow& Lib "user32" ()
'Declare Function GetWindowTextLengthA& Lib "user32" (ByVal'hwnd&)
Declare Sub GetWindowTextA Lib "user32" _
(ByVal hwnd&, ByVal lpsz$, ByVal cbMax&)
'use Windows functions to obtain a string with the
'title of the current window. The string is returned
'as the value of the ActiveWindowTitle function.
Function ActiveWindowTitle$()
Dim ActiveWindow As Long
Dim TitleLen As Long
Dim Title As String
ActiveWindow = GetForeqroundWindow()
TitleLen = GetWindowTextLengthA(ActiveWindow)
Title$ = Space$(TitleLen)
GetWindowTextA ActiveWindow, Title$, TitleLen + l
ActiveWindowTitle$ = Title$
End Function
'Use the window title -in this case, display it.
'More commonly if would be compared .
Sub Main()
MsgBox ActiveWindowTitle$
End Sub