#1
|
|||
|
|||
Focus a new Document and bring it in the foreground
Hello!
Before you look at the code some details: I have a local addin (autostart). I use this for a form. The form collects templates form different places. I want to select a template and add a new document. Without problems I can add text to the new document by vba. At the end I close the form with "end". My problem: the new docment is not in the foreground. To fix my problem I started (without without an addin) by this way: ------------------ Option Explicit Private Declare Function WindowFromAccessibleObject Lib "oleacc.dll" ( _ ByVal IAcessible As Object, ByRef hWnd As Long) As Long Private Declare Function GetForegroundWindow Lib "user32.dll" ( _ ) As Long Private Declare Function AttachThreadInput Lib "user32" ( _ ByVal idAttach As Integer, _ ByVal idAttachTo As Integer, _ ByVal fAttach As Integer) As Integer Private Declare Function GetWindowThreadProcessId Lib "user32.dll" ( _ ByVal hWnd As Long, _ lpdwProcessId As Long) As Long Private Declare Function SetForegroundWindow Lib "user32.dll" ( _ ByVal hWnd As Long) As Long Private Declare Function BringWindowToTop Lib "user32" ( _ ByVal hWnd As Long) As Long Public Declare Function GetActiveWindow Lib "user32" () As Long Sub test() Dim docnew As Document Dim idThreadForeground Debug.Print GetForegroundWindow Debug.Print GetActiveWindow idThreadForeground = GetWindowThreadProcessId(GetForegroundWindow, 0) Application.WindowState = wdWindowStateMinimize Set docnew = Documents.Add docnew.Activate debug.Print GetForegroundWindow Debug.Print GetActiveWindow Application.WindowState = wdWindowStateMaximize End Sub ------------------- but without success! I can't identify the new document. Need Your help!!! Fabian |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to keep a presentation allways on the foreground | kuyperlu | PowerPoint | 1 | 06-22-2016 06:23 AM |
Change focus from userForm back to word document to see results. | Hank Smith | Word VBA | 1 | 08-11-2014 05:00 AM |
how keep word document highlighted when switching focus to another application? | dylansmith | Word | 4 | 05-08-2013 01:21 AM |
Show userform without losing document focus? Or other method to get a graphic to pop? | AlexR | Word VBA | 7 | 03-31-2013 12:17 PM |
Setting focus to specific word document from UserForm | SaneMan | Word VBA | 5 | 04-01-2011 03:11 PM |