Prev: Editing Paragraph Line Spacing using macro; need help
Next: Word Form / Fields or VBA / calculate on print
From: Anthony on 23 Feb 2010 13:24 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
From: Doug Robbins - Word MVP on 23 Feb 2010 14:53 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 "Anthony" <excelmodeling(a)gmail.com> wrote in message news:5734e5e7-dbed-4691-b922-d91be5e4fccb(a)o3g2000vbo.googlegroups.com... > 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
From: Anthony on 23 Feb 2010 19:43
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 |