Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

Assign the Title & the fulname path of the top Word window to vars

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marceepoo - 28 Nov 2005 00:24 GMT
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
Jonathan West - 28 Nov 2005 12:20 GMT
You don't need all this Windows API stuff in Word VBA for this purpose.

The filename can be read from ActiveDocument.Name

The full pathname can be read from ActiveDocument.FullName

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> I've been trying to figure out how to assign the Title (e.g. "Title$" and
> the
[quoted text clipped - 51 lines]
> MsgBox ActiveWindowTitle$
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.