初投稿のどんぐりすです。 当方Windows10 + EXCEL2010のVBAで、エクセルをアクティブにするためのAppActivateが正常に動作せず、とても困っていました。 ※2021年4月19日追記 まず、AppActivateが正常に動作しないことについて確認します。 3秒以内にエクセル以外のアプリケーションをアクティブにします。 本来であれば3秒後にエクセルが最前面に来てアクティブとなるはずですが、タスクバーのエクセルのアイコンが点滅するだけでアクティブとはなりません。 うーん、困った・・・ 点滅しているということは、アクティブにしようとしたけども何らかの理由でアクティブにできなかったものと思われます。 このエクセルがタスクバーで点滅している状態で、アプリケーション選択のショートカットキー「Alt+Tabキー」を1回押すとエクセルを最前面に持ってくることができるようです。 そこで、先のTest1()モジュールにの最後に1行追加して、Test2()を作成しました。 これを実行するとうまく行きました! つまり、 AppActivateを実行してみて、エクセルがアクティブになっていない場合に、Sendkeyの処理をすればいいということになります。 Private Declare Function GetForegroundWindow Lib "user32" () As Long Sub Test3() このモジュールで、ようやくエクセルを確実にアクティブにできるようになりました。 前提・実現したいことマクロエクセルを開くと、自動でファイルの読み込みと、 下記のようなコードを組むことで、 Private Sub Workbook_Open() ’(他ファイルの読み込み部(略))
End Sub 発生している問題・エラーメッセージ
該当のソースコード
試したこと デバックをすると、※1部のExcel.applicition.captionが別のエクセルファイルになっていました(元々開いていたやつ) 補足情報(FW/ツールのバージョンなど)Excel2019
The AppActivate statement requires the title of the title window. In any case, here's another approach. First, assign your workbook to an object variable, and then refer to that variable when you want to activate that workbook. For example, you can assign your workbook as follows... Code:
or Code: Then, to active the workbook... Hope this helps!
Domenic, Thanks again,
Both methods should work. However, I've just tested the line of code that shows the Print Setup dialog box in Excel 2016. The dialog box pops up, and a printer can be selected, but there's no OK button that can be selected. There's only a Cancel button, a greyed out Options button, and a Set as Default Printer button. Do you get the same thing? Maybe this is prevented the code from
continuing?
I agree both methods should work. Unfortunately they are not. I just tested the same code with wdDialogFilePrintSetup line commented out, and it sets focus on the word doc then refuses to set focus on the Excel App, so I believe that is not the cause of the problem...
Try posting your complete code so that we can have a look at it...
Code: Code:
|