I had being reviewing the forum and trying several ideas but still have the problem. I am running Access 2013, in a form I hit a button to spell and grammar check a text field. The check is done properly using the Word Grammar check. So far so good. But, once Word is closed I activate Access but it stays blinking in the taskbar and I have to click on it to continue working. I want Access back into the screen to continue working as normal.
The code is the following:
Private Sub Comando2_Click()
Dim objWord As Word.Application
Dim doc As Word.Document
accessid = GetCurrentProcessId
accesshwnd = Application.hWndAccessApp
Set objWord = CreateObject("Word.Application")
With objWord
Set doc = .Documents.Add
.Selection.Text = Me.Texto0
docum = doc & " - Word"
.Visible = True
VBA.AppActivate (docum)
.Visible = False
.Dialogs(wdDialogToolsSpellingAndGrammar).Show
If Len(.Selection.Text) <> 1 Then
Me.Texto0 = .Selection.Text
' spellcancell = False
Else
' spellcancell = True
End If
doc.Close wdDoNotSaveChanges
.Quit
End With
Set objWord = Nothing
AppActivate (accessid)
SetForegroundWindow accesshwnd
End Sub
Thanks in advance for your help Regards
As mentioned above, I want Access back into the screen to continue working as normal. I have tried to activate it by Hwnd, SetForegroundWindow and lots of other ideas read in the forum... nothing worked
I found a workaround, it is not ideal, but at least it works till I get a better solution.
Thanks for your help, made me think in a differet way:
AppActivate GetCurrentProcessId
SendKeys "%{TAB}", True
SendKeys "{TAB}", True