Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-27-2020, 03:36 PM
f__s f__s is offline Focus a new Document and bring it in the foreground Windows 10 Focus a new Document and bring it in the foreground Office 2016
Novice
Focus a new Document and bring it in the foreground
 
Join Date: Apr 2020
Posts: 1
f__s is on a distinguished road
Default 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
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Focus a new Document and bring it in the foreground 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
Focus a new Document and bring it in the foreground how keep word document highlighted when switching focus to another application? dylansmith Word 4 05-08-2013 01:21 AM
Focus a new Document and bring it in the foreground 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
Focus a new Document and bring it in the foreground Setting focus to specific word document from UserForm SaneMan Word VBA 5 04-01-2011 03:11 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:57 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft