N
N
Nadim Zakirov2021-01-14 11:34:26
Visual Basic
Nadim Zakirov, 2021-01-14 11:34:26

How to use a macro to set focus to the current document?

I can’t transfer the focus to the document from which the macro is launched, that is, it is necessary to force the focus back to the abandoned document, after which the macro will complete its work. Tried different ways, but none of the options worked:

ThisDocument.Activate
ThisDocumnet.SetFocus
Documents(ThisDocument.Name).Activate

Searched on the net, did not find anything working. Does anyone know a solution to the problem?

spoiler
В крайнем случае, чтобы сфокусировать юзера, я бы мог автоматически закрыть все документы кроме текущего, но мне это решение не нравиться, так как тогда получается фактически я за юзера сохранил все документы с которыми он параллельно работал, а вдруг какие-то не надо было сохранять? Короче, не вариант.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2021-01-14
@zkrvndm

Sub Activate()

  Dim wdApp As Word.Application
  Dim wdDoc As Word.Document
  Dim wdDocTwo As Word.Document

  Set wdApp = CreateObject("word.Application")
  wdApp.Visible = True
  Set wdDoc = ThisDocument
  Set wdDocTwo = wdApp.Documents.Add


  wdDocTwo.Activate 'активация окна( но не выводит на передний план)
  AppActivate (wdDocTwo.Name)' выведет окно wdDocTwo на передний план
End Sub

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question