[英]AppActivate works in Excel 2007 but not in 2010
我有一個在Excel 2007中運行的excel宏,它會打開大型機應用程序,因此我可以自動從電子表格中導入數據。
這一直很好,但是在Excel 2010中不起作用。
我嘗試使用shell命令來使用ID,但另一個應用程序是大型機應用程序,而不是基於Windows的應用程序。
然而,
AppActivate“標題”(打開大型機應用程序)在excel 2007中運行良好。
在Excel 2010中,我收到運行時錯誤5-無效的過程調用或參數。
我已經嘗試解決了兩天,並且在2007版本上一切正常。
任何幫助將非常感激。
昏暗的appName作為字符串
appName = Range(“ AppName”)。Value'這是存儲在我的excel電子表格中的大型機應用程序的名稱
AppActivate(appName)=>此行給出運行時錯誤“ 5”,無效的過程調用或參數
我找到了這段代碼,希望對您有所幫助:
Dim Myself as string
Myself = activewindow.caption
然后,AppActivate(Myself)會將焦點重新回到原始電子表格。
但是,在“升級”之后,AppActivate行開始出現錯誤,並且我最終發現,如果我只有一個打開的電子表格,則Windows任務欄中的標題就是“ Microsoft Excel”。
我通過更改為
Myself = "Microsoft Excel - " & activewindow.caption
https://www.mrexcel.com/forum/excel-questions/566273-appactivate-excel-2010-a.html
如果要將焦點返回到VBC代碼所在的Excel(又名ThisWorkbook
對象),則可以使用以下行:
AppActivate Title:=ThisWorkbook.Application.Caption
當AppActivate沒有確切的標題時,就會出現此錯誤。 您可以嘗試下面的代碼,看看是否有幫助。
Public Sub AppActTest()
Dim objWd As Object
Dim objTsk As Object
Dim blOpenedByCode As Boolean
On Error Resume Next
Set objWd = GetObject(, "Word.Application")
If objWd Is Nothing Then
Set objWd = CreateObject("Word.Application")
blOpenedByCode = True
End If
On Error GoTo 0
For Each objTsk In objWd.Tasks
If InStr(objTsk.Name, "MainframeApplicationName") > 0 Then
objTsk.Activate
objTsk.WindowState = wdWindowStateMaximize
Exit For
End If
Next
If blOpenedByCode Then objWd.Quit
Set objTsk = Nothing
Set objWd = Nothing
End Sub
這將需要在您的計算機上安裝Microsoft Word。 它將與部分匹配一起使用。
感謝您的回答,我稍后才發現我的用戶正在從遠程位置啟動Excel 2016版本,因此顯然找不到他們嘗試打開的應用程序。 Excel的早期版本是從其桌面啟動的,因此可以正常工作。
簡而言之,AppActivate函數對於兩個Excel版本都可以正常工作。
謝謝你的時間。
問候
我使用此宏從Firefox中的Excel 2010打開書簽。
它已經起作用了-有時有時不起作用(運行時錯誤5)
我認為此修復程序是:關閉並重新打開Firefox,然后嘗試-工作
什么弄亂了,所以不起作用?
Sub Open_a_Bookmark(control As IRibbonControl)
' Open a Bookmark in Firefox . . . Firefox has to be open for this to work
' Go to the Row of the bookmark you want, then click this button.
' It automatically goes to the URL column, and copies it.
Cells(ActiveCell.Row, "BK").Activate
ActiveCell.copy
' Open a new tab in Firefox with Ctrl+T
AppActivate "Firefox"
SendKeys ("^t"), True
' Sometimes you have to click this macro again, to get it to work, because the "paste" doesn't get to Firefox.
' Give it a second before pasting
Application.Wait (Now + TimeValue("00:00:01"))
' The focus defaults to the Address Bar. Paste the URL / Enter
SendKeys ("^v~"), True
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' See the bottom of "Process_Bookmarks" for details. Used at the end of macros, when necessary.
SendKeys "{NUMLOCK}", True
Application.Wait (Now + TimeValue("00:00:01"))
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.