Forum Discussion
VBA code to bring the active document in front
I have a subroutine that produces and edits six different documents.
My current problem is that the documents all stay in the background. But, I want them to be in front of all other windows using only VBA and without APIs.
I've looked for code to do that and they either use APIs or create a new document.
I tried this code:
Sub Generate_Motion()
Call Initiations
Documents.Add Template:=pathInputDoc & "\Template.dotx"
Dim wdApp As word.Application
Dim word As word.Document
Set wdApp = GetObject(ActiveDocument, "Word.Application")
wdApp.Visible = True
With ActiveDocument
...
End Sub
but it gives me an error.
Is there way to bring an already-open document in front using only VBA code?
3 Replies
- Charles_KenyonBronze Contributor
I do not know that this will do what you want but you can get the count of open documents and activate one by the activate command. For example:
Documents(4).Activate
That should move document 4 to the top.
Question: Are you trying to animate Word? PowerPoint is far better for this and you do not need vba to do it. If in Word, you would want to be moving objects/images to the top in the document, not entire documents.
- KlaCatCopper Contributor
I could probably just do
ActiveDocument.Activate
but what's the difference between doing that and
ActiveDocument.Visible = True
?
The Window.Visible property determines if a document window is visible in the user interface or not (see https://learn.microsoft.com/en-us/office/vba/api/word.window.visible). It doesn't have anything to do with activating Word windows.