Grazie Osvaldo, eccomi qua:
1- Questo è il codice del modulo che richiama Word in primo piano
Option Compare Database
#If Win64 Then
Private Declare PtrSafe Function BringWindowToTop Lib "USER32" ( _
ByVal HWnd As Long) As Long
Private Declare PtrSafe Function FindWindow Lib "USER32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function SetFocus Lib "USER32" ( _
ByVal HWnd As Long) As Long
#Else
Private Declare Function BringWindowToTop Lib "user32" ( _
ByVal HWnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SetFocus Lib "user32" ( _
ByVal HWnd As Long) As Long
#End If
Public Sub ActivateWord()
Dim Res As Long ' General purpose Result variable
Dim DocHWnd As Long ' Window handle of Excel
Const C_MAIN_WINDOW_CLASS = "OpusApp"
DocHWnd = FindWindow(lpClassName:=C_MAIN_WINDOW_CLASS, _
lpWindowName:=vbNullString)
If DocHWnd > 0 Then
Res = BringWindowToTop(HWnd:=DocHWnd)
If Res = 0 Then
Debug.Print "Error With BringWindowToTop: " & _
CStr(Err.LastDllError)
Else
SetFocus HWnd:=DocHWnd
End If
Else
Debug.Print "Can't find Word"
End If
End Sub
2- Questo è quello che si attiva al click sugli specifici pulsanti:
Option Compare Database
Sub ApriFile(NomeFile As String)
Dim appword As Object 'Word.Application
Dim doc As Object 'Word.Document
Dim fPath As String
Dim FName As String
On Error Resume Next
Set appword = GetObject(, "Word.Application")
Error.Clear
If Err.Number <> 0 Then
Set appword = CreateObject("Word.Application")
End If
appword.Visible = True
fPath = "C:\Gestione\Moduli\"
FName = NomeFile
With appword
Set doc = .Documents.Open(fPath & FName)
'.Activate
ActivateWord
End With
With doc
.Bookmarks("Cognome").range.insertAfter Me.Cognome
.Bookmarks("Nome").range.insertAfter Me.Nome
.Bookmarks("Data_di_nascita").range.insertAfter Me.Data_di_nascita
End With
Set doc = Nothing
Set appword = Nothing
End Sub
Private Sub Comando23_Click()
Call ApriFile("Visita Ostetrica.dotx")
End Sub
Private Sub Comando24_Click()
Call ApriFile("Visita Ginecologica.dotx")
End Sub
Private Sub Comando25_Click()
Call ApriFile("Ecografia 5-10 Sett..dotx")
End Sub
Private Sub Comando26_Click()
Call ApriFile("Ecografia I° Trimestre.dotx")
End Sub
Private Sub Comando27_Click()
Call ApriFile("Ecografia Pelvica.dotx")
End Sub
Private Sub Comando28_Click()
Call ApriFile("Ecografia Morfologica.dotx")
End Sub
Private Sub Comando29_Click()
Call ApriFile("Ecografia II° Trimestre.dotx")
End Sub
Private Sub Comando30_Click()
Call ApriFile("Ecografia III° Trimestre.dotx")
End Sub
Vedi un pò tu se riesci a cavarne un ragno dal buco.