我最近升级到 Office 365 / Excel 2016 导致了一些不必要的行为变化。Workbook("Portfolio Appreciation") 包含一个 Workbook_open 过程,它检查 Workbook("Index Returns") 是否打开;如果不是,它将打开该工作簿。
使用 Excel 2007,Index Returns
将在后台打开并留在那里,这是所需的行为。它将在“窗口中”,并且可以在同一个 Excel 窗口中使用功能区选项卡Arrange All
上的选项进行查看。Window
View
对于 Excel 2016,如果它由 Workbook_Open 过程Index Returns
打开,则会在其自己的 Excel 窗口中打开,并在前面结束。(不能再在与 相同的 Excel 窗口中查看Portfolio Appreciation
)。
Index Returns
前面的事实就是问题所在。
我尝试选择和取消选择忽略使用 DDE 的其他应用程序的选项;我已经尝试了该AppActivate
方法(如下面的代码所示)并使用 验证了MsgBox
该参数与相关标题栏匹配。
不知道下一步该去哪里。建议表示赞赏。
另外: Index Returns
不包含宏或连接。 Portfolio Appreciation
不包含宏, Workbook_Open
并且确实有一个在打开时会刷新的 Web 查询(该查询会下载一些股票索引的内容)。
Option Explicit
Private Sub Workbook_Open()
Dim wbs As Workbooks, wb As Workbook
Dim IndexReturns As String
Dim re As RegExp
Const sPat As String = "(^.*\\DATA\\).*"
Const sRepl As String = "$1EHC\Investment Committee\indexreturns.xlsb"
Dim sTitle As String
sTitle = Application.Caption
Set wbs = Application.Workbooks
Set re = New RegExp
With re
.Pattern = sPat
.Global = True
.IgnoreCase = True
End With
IndexReturns = re.Replace(ThisWorkbook.FullName, sRepl)
For Each wb In wbs
If wb.FullName = IndexReturns Then Exit Sub
Next wb
Application.ScreenUpdating = False
wbs.Open (IndexReturns)
Set re = Nothing
AppActivate sTitle 'sTitle contains title of thisworkbook
'The below doesn't work either
'AppActivate ThisWorkbook.Application.Caption
Application.ScreenUpdating = True
End Sub