標題:
[發問]
如何取得己開啟EXCEL控制權,執行外部檔案巨集
[打印本頁]
作者:
blue2263
時間:
2019-7-9 12:00
標題:
如何取得己開啟EXCEL控制權,執行外部檔案巨集
請教大大
附檔1 & 2由兩個EXCEL各別打開後,
執行1.xlsb OpenApp巨集,如下程式碼,
檔案在己開啟的狀態下,如何取得己開啟EXCEL控制權?,執行2.xlsb測試巨集
[attach]31007[/attach]
Private Sub OpenApp()
On Error Resume Next
Err.Clear
Open ThisWorkbook.Path & "\" & 2 & ".xlsb" For Append As #1
Close #1
If Err.Number > 0 Then '此活頁簿己被開啟
'此活頁簿己被開啟,此處要如何取得己開啟EXCEL控制權?,執行測試巨集
app1.Run "測試"
Else
Set app1 = CreateObject("Excel.Application")
Set book1 = app1.Workbooks.Open(ThisWorkbook.Path & "\2.xlsb")
app1.Visible = True
app1.Run "測試"
End If
Set app1 = Nothing
Set book1 = Nothing
End Sub
複製代碼
作者:
blue2263
時間:
2019-7-18 21:15
我己在網路上找到解答 ,提供給需要的朋友
https://tw.answers.yahoo.com/question/index?qid=20090214000016KK01619
Private Sub OpenApp()
Dim app1 As Object
On Error Resume Next
Err.Clear
Open ThisWorkbook.Path & "\" & 2 & ".xlsb" For Append As #1
Close #1
If Err.Number > 0 Then '此活頁簿己被開啟
Set app1 = CreateObject(ThisWorkbook.Path & "\" & 2 & ".xlsb")
app1.Application.Run "測試"
Else '此活頁簿未被開啟
Set app1 = CreateObject("Excel.Application")
Set book1 = app1.Workbooks.Open(ThisWorkbook.Path & "\2.xlsb")
app1.Visible = True
app1.Run "測試"
End If
Set app1 = Nothing
Set book1 = Nothing
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)