code to close

  • Thread starter Thread starter fordge
  • Start date Start date
F

fordge

I have a workbook that references another workbook. The
referenced workbook automatically opens. Is there a code
I can put in VBA that will also close the referenced
workbook when the source workbook is closed?


Another question, when my options are set to view note and
indicator, how come when I open a workbook with notes
already in it, the note is not visible except when the
cursor hovers over the cell?
 
Is there a code I can put in VBA that will also close the referenced
workbook when the source workbook is closed?

If you can remove the reference first then you can close both workbooks.
This worked for me when the main workbook with this code had a reference to
Book1.xls whose VB project was named "xxx" (rather than VBAProject) to avoid
a conflict.


Private Sub Workbook_BeforeClose(Cancel As Boolean)
With ThisWorkbook.VBProject.References
.Remove .Item("xxx") ''VBAProject name in Book1.xls
End With
Workbooks("Book1.xls").Close False
ThisWorkbook.Saved = True
End Sub

visible except when the cursor hovers over the cell?

The Comment and Indicator option is a weird one. When you turn it on or off
it affects all open workbooks. But any workbook you open afterward opens
with its setting intact. So it's a hybrid work level/application level
setting.
 
Back
Top