Skip to main content
Mycological
Participant
May 8, 2019
Answered

GetActiveDoc does not find a minimized window

  • May 8, 2019
  • 3 replies
  • 1945 views

Running Windows 7, Acrobat Pro DC, Excel vba

I'm finding that the following code does not find the active document if the active document is minimized.

Otherwise the code works fine.

Is there a better method? I would like my code to find a minimized window as an active document.

I haven't found any reference to this in Adobe Acrobat SDK documentation.

Thanks

Dim pdApp As acrobat.CAcroApp

Dim pdDoc As acrobat.CAcroPDDoc

Dim pdFile As acrobat.CAcroAVDoc

Set pdApp = CreateObject("AcroExch.App")
Set pdDoc = CreateObject("AcroExch.PDDoc")
Set pdFile = pdApp.GetActiveDoc

If (pdFile Is Nothing) Then
MsgBox "nothing"
End If

This topic has been closed for replies.
Correct answer BarlaeDC

Hi,

Could you not use GetAVDoc ( long nIndex), and pass in the index as you know how many documents you have this should always be able to get the document you want.

Regards

Malcolm

3 replies

Legend
May 9, 2019

You can't necessarily activate it. For example, if the user selects the Tools tab their document might become inactive, and you cannot change the tabs displayed. You can try activating it but be prepared for failure.

Mycological
Participant
May 9, 2019

True if the user has the tools tab selected, the routine will not find it.

However, the case of minimizing is a much more likely case for the user to encounter.

For this application using the GetAVDoc method does work although I need to fine tune things a bit.

        Dim pdApp As acrobat.CAcroApp

        Dim pdDoc As acrobat.CAcroPDDoc

        Dim pdFile As acrobat.CAcroAVDoc

        Dim pdAVdoc As acrobat.CAcroAVDoc

Set pdApp = CreateObject("AcroExch.App")
Set pdDoc = CreateObject("AcroExch.PDDoc")
Set pdAVdoc = pdApp.GetAVDoc(0)

If pdAVdoc Is Nothing Then
MsgBox "not getting AVDoc"

Exit Sub
End If

pdAVdoc.BringToFront


Set pdFile = pdApp.GetActiveDoc

If (pdFile Is Nothing) Then
MsgBox "The survey Home or Tools tab cannot be selected."

Exit Sub
End If

BarlaeDC
Community Expert
BarlaeDCCommunity ExpertCorrect answer
Community Expert
May 9, 2019

Hi,

Could you not use GetAVDoc ( long nIndex), and pass in the index as you know how many documents you have this should always be able to get the document you want.

Regards

Malcolm

Legend
May 8, 2019

If it’s mimimized it isn’t active. Often there is no active doc despite having open docs. You can enumerate all open docs and decide what to do in this case but take care - how will you pick one?

Mycological
Participant
May 9, 2019

Well earlier in the code I do enumerate open docs and if more than 1 or 0 the user is alerted and then exit sub.

So if there is only one doc open and its minimized, but I do not know the file name can I activate that doc?