AppActivate works in Excel 2007 but not in 2010

痴心易碎 提交于 2019-12-06 11:28:51

I found this code, hope it helps:

Dim Myself as string
Myself = activewindow.caption

Then AppActivate(Myself) would take focus back to the original spreadsheet.

After the "upgrade", however, the AppActivate line started giving me errors, and I finally figured out that if I only had a single open spreadsheet, the title in the Windows Task Bar was just "Microsoft Excel".

I made a temporary fix by changing to

Myself = "Microsoft Excel - " & activewindow.caption

https://www.mrexcel.com/forum/excel-questions/566273-appactivate-excel-2010-a.html

If you want to return the focus back to the Excel where your VBC code lies, aka ThisWorkbook object, then you can use the following line:

AppActivate Title:=ThisWorkbook.Application.Caption

This error comes when the AppActivate doesn't get exact title. You can try below code and see if it helps you.

    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

It will require Microsoft Word to be installed on your computer. It will work with partial match.

Thanks for the answers, I only found out later that my users were launching the Excel 2016 version from a remote location, so the application they were trying to open could obviously not be found. The previous version of Excel was launched from their desktop so it worked.

In a nutshell, the AppActivate function works fine for both Excel version.

Thanks for your time.

Regards

sludge705x

I use this macro to open Bookmarks from Excel 2010 in Firefox.

It has worked - then sometimes it doesn't work (Run-time error 5)

I see the fix as: close & re-open Firefox, then try it - works

What gets messed up, so it doesn't work?

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!