例えば、
[標準モジュール]
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Sub Macro1()
UserForm1.Show vbModeless
End Sub
[Sheet1モジュール]
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If FindWindow(vbNullString, "UserForm1") <> 0 Then
UserForm1.TextBox1 = ActiveCell.Text
AppActivate UserForm1.Caption
End If
End Sub
<Book1.xls>
[標準モジュール]
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Sub Macro1()
UserForm1.Show vbModeless
End Sub
Sub Macro2(ActiveCellText)
UserForm1.TextBox1 = ActiveCellText
AppActivate UserForm1.Caption
End Sub
[Sheet1モジュール]
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If FindWindow(vbNullString, "UserForm1") <> 0 Then
UserForm1.TextBox1 = ActiveCell.Text
AppActivate UserForm1.Caption
End If
End Sub
<Book2.xls>
[標準モジュール]
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
[Sheet1モジュール]
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If FindWindow(vbNullString, "UserForm1") <> 0 Then
Application.Run "Book1.xls!Macro2", ActiveCell.Text
End If
End Sub