Forum Discussion

KlaCat's avatar
KlaCat
Copper Contributor
Sep 16, 2023

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_Kenyon's avatar
    Charles_Kenyon
    Bronze Contributor

    KlaCat 

    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.

     

     

     

     

Resources