AppActivate does not completely restore focus

Ian 1 Reputation point
2022-12-15T22:38:25.393+00:00

I have a macro where I open a hyperlink from a cell into a web browser. Then a series of input boxes will appear prompting the user to answer questions about the opened window.

The browser does not need to be interacted with, only viewed, and I am trying to restore focus to the excel worksheet to allow for the prompts to be answered without needing to manually alt tab.

I have previously been able to do this with AppActivate, but recently, and for reasons I cannot discern, AppActivate will not restore focus to the worksheet. Strangely, it seems to impart a sort of quasi focus, as if I do not include the AppActivate line, the prompt will not appear until I manually restore focus to the workbook. If I do include the AppActivate line, the prompt will appear automatically, but I cannot interact with it until I manually restore focus to the workbook.

Apologies if this has been addressed before, but I've looked and cannot find anyone reporting a similar issue. Please note this is NOT a spelling issue. I have tried manually typing the workbook name into the code (e.g. AppActivate "worksheetname - Excel"), and it does not help.

Here is what I am trying to use.

Dim ref As String
ref = ThisWorkbook.Application.Caption

Do Until IsEmpty(ActiveCell.Value)

ThisWorkbook.FollowHyperlink (ActiveCell.Value)
Application.Wait (Now + TimeValue("0:00:05"))
AppActivate (ref)

ActiveCell.Offset(0,1).Select
ActiveCell.Value = InputBox("Question", "Options", default)

'after x prompts the code moves to the next hyperlink
ActiveCell.Offset(1,-x).Select
Loop

Office Visual Basic for Applications
Office Visual Basic for Applications
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Visual Basic for Applications: An implementation of Visual Basic that is built into Microsoft products.
1,502 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.