Syntax to close Workbook

E

Eddie_SP

Hi !

I have one Multipage with 6 pages.
When I click on the last page, it opens a workbook from the Server.
But when people click on any other page instead of last one, I need a
command to close this activeworkbook.

I tried in "Select Case" but it doesn't help me, because I will have to
change the body of the program...

I just needed something like:

IF ACTIVEWORKBOOK IS DIFFERENT FROM THIS WORKBOOK THEN

ACTIVEWORKBOOK.CLOSE FALSE


I just do not get the right syntax...


And if someone has a tip to give me about closing this recently opened file
in case someone choose another page, please feel free, it would help me a
lot !
 
P

Patrick Molloy

If ActiveWorkbook.Name <> ThisWorkbook.Name then
ActiveWorkbook.Close false
End If
 
J

Jacob Skaria

Hi

Another way to deal with that is to store the workbook names in the Tag
property of each Page; and use the Change event; to close if open and Open
the workbook related to that page....

Dim wb As Workbook
Private Sub MultiPage1_Change()
If Not wb Is Nothing Then wb.Close False
Set wb = Workbooks.Open("c:\" & MultiPage1.SelectedItem.Tag)
'your code continues
End Sub

If this post helps click Yes
 
E

Eddie_SP

Jacob, this is great man !

Thank you very much for the tip.

Both methods worked perfectly !

Tks. =)
 
J

Jacob Skaria

Do you mean

Sub Macro1()
ActiveSheet.Columns(7).Insert
ActiveSheet.Range("G1") = "Title"
End Sub

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top