Word VBA Tasks.Exists()、AppActivate()函式的替代方案
菩薩慈悲:
非常需要此技術,幸好遇到您此大作,乃知Chrome的 Class Name 原來是 「Chrome_WidgetWin_1」,另有「Chrome_RenderWidgetHostHWND」的說法,詳:
https://stackoverflow.com/questions/19705797/find-the-window-handle-for-a-chrome-browser
也因此末學才能在Word VBA 實現 AppActivate()函式的替用(因為它有時會當。可剛才用此新程式好像也會。唉。)
以下是末學實作的程式碼片段,餘詳 GitHuB。感恩感恩 南無阿彌陀佛:
https://github.com/oscarsun72/TextForCtext/blob/e88f7d0864a0dc39d439ae199055fb7cc5b3dbde/WordVBA/%E6%96%87%E5%AD%97%E8%99%95%E7%90%86.bas#L3137
https://github.com/oscarsun72/TextForCtext/blob/e88f7d0864a0dc39d439ae199055fb7cc5b3dbde/WordVBA/SystemSetup.bas#L378
If Not SystemSetup.appActivatedYet("chrome") Then
'If Not word.Tasks.Exists("google chrome") Then
Shell SystemSetup.getChrome & " https://dict.revised.moe.edu.tw/search.jsp?md=1"
Else
' AppActivate "google chrome" 'https://docs.microsoft.com/zh-tw/sql/ado/reference/ado-api/absoluteposition-property-ado?view=sql-server-ver15
'try looking for both Chrome_WidgetWin_1 and Chrome_RenderWidgetHostHWND
SystemSetup.apicShowWindow "Chrome_WidgetWin_1" _
, vbNullString, 3 'https://zechs.taipei/?p=146
'https://docs.microsoft.com/zh-tw/visualstudio/debugger/how-to-start-spy-increment?view=vs-2022
'https://stackoverflow.com/questions/19705797/find-the-window-handle-for-a-chrome-browser
End If
sues-with-show-window-activation.920147/
Public Declare Function ShowWindow Lib "user32" _
(ByVal hWnd As Long, ByVal nCmdSHow As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Boolean
Function apicShowWindow(strClassName As String, strWindowName As String, lngState As Long)
'https://www.mrexcel.com/board/threads/vba-api-call-issues-with-show-window-activation.920147/
'Declare variables
Dim lngWnd As Long
Dim intRet As Integer
lngWnd = FindWindow(strClassName, strWindowName)
apicShowWindow = ShowWindow(lngWnd, lngState)
'Spy + + :https://docs.microsoft.com/zh-tw/visualstudio/debugger/how-to-start-spy-increment?view=vs-2022
SetForegroundWindow lngWnd 'https://zechs.taipei/?p=146
End Function
留言