私はxlsmファイルフォームを使用して、ユーザーに開くブックを選択するように指示する2番目のフォームを呼び出します。 VBAコードはそのワークファイルを開きます。しかし、Office 2016では、元のxlsmファイルの後ろにファイルが開きます。つまり、アクティブウィンドウにはなりません。 Alt + Tabを使用して開いているファイルに移動することはできますが、元のxlsmファイルをアクティブにするまでAlt + Tabキーを押すまで、ファイルはキーストロークまたはマウスクリックと対話しません。その後、私はVBAオープンファイルを反応させるとき、私はそれと対話することができます。つまり、VBAを開いたファイルは、VBAコードを持つワークファイルでベースを元に戻すまでアクティブになりません。私は一連の作業ワークブック、application.activewindowコマンドを使用して、開かれたワークブックを無駄にすることを試みました。VBAを使用してExcelブックを開くときに、開いているブックをアクティブなウィンドウにする方法はありますか?
Private Sub btn_select_Click()
' User clicks on select. If a subcategory is selected open the file and stop program. If not repopulate sub-category
If IsNull(lst_subcategories) Or lst_subcategories = "" Then
lst_subcategories.Clear
Call populate_data
Else ' open file and unload form (End)
If lst_datacategories <> "Tourism" Then
str_filetoopen = "I:\Bureau-Work\Data System\" & lst_datacategories & "\" & lst_subcategories & ".xlsx" ' May need to be F: drive
Else
str_filetoopen = "I:\Bureau-Work\Data System\" & lst_subcategories & "\" & lst_subcategories & ".xlsx" ' May need to be F: drive
End If
On Error Resume Next ' drive or file may not be available. If so error and retain from
Set wb = Workbooks.Open(str_filetoopen)
If wb Is Nothing Then
MsgBox "I: Drive or Retrieve File is Not Accessible"
GoTo handle ' retains frm_editData
End If
Workbooks(wb).Activate
ActiveWindow.Visible = True
End 'exit all macros and forms once successfully loading file
End If
handle:
End Sub
「ワークブック(WB).Activate」と「Activewindow.visible =真」コマンドがアクティブとして新規ブックウィンドウを設定しようとしている。ここで
は、私が使用しているコードです。窓。私の知る限り、これは、Office 2013で発生しませんが、あなたのVBAスクリプトの最後にこれを追加2016年
ため
作品を新しいブックのセル/範囲/シートを選択? –