我想打开一个工作簿 (WB1),然后在打开它的同时打开另一个工作簿 (WB2)。我想隐藏 WB2。
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Workbooks.Open Filename:="C:\WB2.xlsm"
ActiveWindow.Visible = False
End Sub
这就是我到目前为止所拥有的,它的作用是隐藏两个工作簿。我希望 WB1 保持在顶部并可见。
谢谢!乔什
我想打开一个工作簿 (WB1),然后在打开它的同时打开另一个工作簿 (WB2)。我想隐藏 WB2。
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Workbooks.Open Filename:="C:\WB2.xlsm"
ActiveWindow.Visible = False
End Sub
这就是我到目前为止所拥有的,它的作用是隐藏两个工作簿。我希望 WB1 保持在顶部并可见。
谢谢!乔什
an important part would seem to be how to turn view back on again. other post is the answer.. i just had to see it work before i commited it. hope this is enough to explain it, may have been done in less space. thanks.
i would have to agree to post a couple words describing the key working line. i am just novice at vb & have to say that 99% of posts require some research to get a needed variable in there. i believe so enough to add some expletives as hours by many can be spent, trying to find the dang answer, but will refrain : ).
the consequence is: everyone on the planet has to spend 2 to infinite hours.
(thanks for having code, to put code in a box, needs some tweaking for lines to include / space lines interfere?).
what i found: changing out may not work: .Visible and .Hidden - have no idea what the 1 in windows(1) is for.
sub TEST1() 'in a module
'if want to happen when you open a wb, place in: "ThisWorkbook" module as:
'Private Sub Workbook_Open()
Dim wb As Workbook
'Set wb = Workbooks("WB2.xlsm") 'YES
'Set wb = Workbooks(Filename:="C:\WB2.xlsm") 'untried should work for path eg
'Set wb = Workbooks.Open(Filename:="C:\WB2.xlsm") 'original, with a command added: open
Application.ScreenUpdating = False
If 0 = 0 Then 'set to: if 0 = 1 to skip test
If wb.WINDOWS(1).Visible = False Then 'TOGGLES: press F5 or run macro button
wb.WINDOWS(1).Visible = True
MsgBox "Workbook is NOT Hidden" & Space(10), vbQuestion 'a good test method
Else
wb.WINDOWS(1).Visible = False '<< line to use, to hide wb on open
MsgBox "Workbook is Hidden" & Space(10), vbQuestion 'a good test method
End If
Else
wb.WINDOWS(1).Visible = False '<< line to use, to hide wb on open
end if
End Sub
Private Sub Workbook_Open()
Dim wb as workbook
Application.ScreenUpdating = False
set wb=Workbooks.Open(Filename:="C:\WB2.xlsm")
wb.Windows(1).Visible = False
End Sub
这似乎是一篇旧帖子,但我想我会添加我的答案版本,因为我正在做类似的事情。
Set m_WB = Workbooks("WB2FilePath\WB2.xlsm")
Windows(m_WB.Name).Visible = False
'Do work
'Set WorkBook to visible
Windows(m_WB.Name).Visible = True
请记住,最好在完成后将 WB2 设置为可见。这样可以避免任何内存在您不知情的情况下在后台被吃掉!
干杯。