index > Visual Basic for Applications (VBA) > VBA w/ Word 2000 - keep form on top of all applications

VBA w/ Word 2000 - keep form on top of all applications


Does anyone know of a way to make a form stay on top of all applications or even on top of all open Word documents? I want a form that stays on top even if I minimize its parent Window (the document from which it was launched). I want it to stay on top even if I click on another Word document. Is it possible?

I've used the SetWindowPos function, but as soon as I minimize the form's parent, the form minimizes as well. I've tried using the SetParent function and the GetDesktopWindow function to make the desktop the forms parent, but for some reason the GetDesktopWindow seemed to return the same handle as the form's parent Word document.

Any help would be greatly appreciated.

msv6

OK - I found the EXACT functionality I want to try to replicate.

msv6

That's called a modal form. Create a new Userform in your document, I'm presuming your using word here. It will be called UserForm1. To display the form use the following code.

Dim usrFrm As New UserForm1
usrFrm.Show vbModal

It will open and stay open until the user deals with whatever is displayed.




www.dsmyth.net/blog
Derek Smyth

Thanks for your post Derek!

Making the form modal doesn't do quite what I'm looking for though. If you try using Word's Cross-reference dialog, you'll notice it's not modal - it will stay on top of whatever Word document you activate, but it will let you move, view, and even modify other documents. When I make my UserForm modal - everything freezes until I close the form. Any Ideas? Is this possible? I thought it would be since Word does it somehow.

Thanks again,

msv6

msv6

Hi msv6,

Thought the old modal form would have done you.. Oh well I think your looking to keep the form on top. Most programming languages have a property of the form to keep it on top of all other applications, VBA doesn't. I believe you'll need to dip into the Windows API to get what your looking for.

This link here might be what your looking for, I haven't ran it

http://www.freevbcode.com/ShowMessage.asp?ID=44299

Also if you do a search for "Always on Top Window in VBA" or a variation of that you might find something better.

Hope thats useful.




www.dsmyth.net/blog
Derek Smyth

Hey Derek - Thanks for your reply. The link you sent me, and most things I find searching for "Always on TOp Window in VBA" all use the same approach: the Windows API call SetWindowPos( ). These solutions make the form stay on top of other forms; but - like Windows Cross-reference dialog - I'm looking for a way to make the UserForm stay on top of any running Word application. I've tried about every Windowing API I could find (including tyring to set the Form as a child to different things), but nothing worked.

I don't have VB 6, I'm just developing with the VBA environment that comes with Word. Initially I was thinking there must be a way to do this, since the Cross-reference dialog does it, but since Word was written in C++ (I think), they could have used threads for the Cross-reference dialog. I don't think you can use threads with just the basic VBA that comes with Word. Maybe what I'm trying to do is not possible (without making a more complicated application with VB 6).

Thanks again for your help!

msv6
reply 6

You can use google to search for other answers

 

More Articles

• Close excel
• filter doesn't seem to be working
• MS Access User Defined Permissions
• Require Basic Excel Sorting Macro To Be Made For Me!!! (Pretty Ba...
• IIf function within MS Access
• Subform Problem
• Web Page Components
• VBA forms for Excel. Always on top ??
• Issues with Updating Sharepoint List...
• How do you create a flashing cell
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• so lost and buried in help printouts
• the function about string "Right()&
• Saving all individual worksheets in a wo
• use Active directory to find ip address
• external file data
• Program aborts only when run with Access
• Map XML elements with VBA
• empty datagrid
• check if workbook is open
• Trying to get VB to update charts in Excel
• OpenRecordset VBA Parameters
• Close Access Form After Video playing
• Optimise VBA for Multi-Processors
• Using ApplyCustomType with variable numb
• Find worksheets starting with "xxxx

Hot Articles

• Need to detect whether Access subform cu
• Need help creating trigger animation wit
• Access 2003 - programming arrow keys wit
• Selecting Data By....
• Lack of mouse scroll wheel support in VBA
• What language was Microsoft Word develop
• Problem sorting dates!
• Setting DisplayFullScreen in Excel: 2 is
• Autosave using VBA after n minutes
• Extracting Text from body of Outlook ema
• Bug or Error ?
• Help with: hiding main menu in Visio 200
• access populate combo box help needed
• additem issue with populating a combobox
• Need to Count the replacements made by a

Recommend Articles

• Using Inet to download an FTP File
• Date validation on a form
• Problem with excel, VBA & Bloomberg-
• Excel ShapesText
• A vector of vectors
• empty datagrid
• access - importing specific data from ex
• passing data from a form to a module
• Colored Named Ranges
• Control Break Trap will not work whilst
• Question about ADO and Access
• RunTime Error 3704 Loading Recordset fro
• Find and Replace Carriage Return in Exce
• How to refer to an object by the tab index
• [off topic] Windows Live Messenger Probl