Search code examples
ms-accessvba

Microsoft access vba-shift focus from access to word


I am creating and opening a word document through access 2007 vba. The document is created but the focus is not shifted to word. Instead the focus still remains on access form through which am creating the doc. Below is my code:

Dim obj As Word.Application
Dim wor As Word.Document
Dim str As String

str = "C:\hello\folder1\vin.dot"

Set obj = CreateObject("Word.Application")
Set wor = obj.Documents.Add

With wor

 .SaveAs str

 .Close
End With


obj.Visible = True
obj.Documents.Open str

obj.WindowState = wdWindowStateMaximize

Any sugesstions please.


Solution

  • You can move the focus with AppActivate;

    AppActivate "Microsoft Word"