Making a UserForm show above a any opened doc

A

Anthony

Hi,

I am using a userform to load document into Word, but when the
document is opened, the userform window will be covered by the opened
file. This happens whether the ShowModal property is set to True or
False.

I checked online and found this posted by Doug:

Making a UserForm show above a newly created Word 2000+
http://www.word.mvps.org/FAQs/Userforms/KeepUserFmAboveDoc.htm

but the link is removed. :(


I also tried to minimize the newly opened file with the following
code:

wrdDoc.Windows(1).WindowState = wdWindowStateMinimize

(The wrdDoc is the file object and I verified the wrdDoc.Name as the
file name.)

but it does not get minimized. However, when I use
activedocument.Windows(1).WindowState = wdWindowStateMinimize, it
works on the document which is running the code.

Could any one help? (I need to know how to make the userform appear
at front and how to minimize a opened doc with VBA.)

Anthony
 
D

Doug Robbins - Word MVP

Try the link again. It just worked here.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
A

Anthony

Thank you so much for your help. The code is cool and works well.

Can the following code be placed in a sub in a module (and not in a
form)?

====================================
Option Explicit
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Sub CommandButton1_Click()
Dim iHandleForm As Long
Dim iHandleDoc As Long
Dim iNull As Long
Dim oDoc As Document

iHandleForm = GetActiveWindow()
Set oDoc = Documents.Add
iHandleDoc = GetActiveWindow()
iNull = SetParent(iHandleForm, iHandleDoc)
oDoc.Activate
End Sub
====================================

If it is doable, how can I make the change to accommodate for that?
(Because I have the
Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
process in a sub already and I am hesitate to move it into the form.)

Anthony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top