View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Leanne Leanne is offline
external usenet poster
 
Posts: 87
Default How to enter a macro that performs when a file is closed

Thank you - there is not much point to knowing these codes if I cant
understand them. Appreciated

"Dave Peterson" wrote:

Mike used:
Sheets("Sheet1").Visible = False
and I used:
thisworkbook.worksheets("Somesheetname").visible = xlsheethidden

I used worksheets(). Mike used Sheets(). If the sheet you're hiding is a
worksheet, either will work.

If the sheet you're hiding is a chart sheet or a dialog sheet or an old macro
sheet, then my code won't work.

I qualified my worksheets() by using ThisWorkbook. I like to qualify objects to
make sure I know what object I'm working with.

..Visible can accept 3 different values.
xlsheetvisible (which is equal to -1)
xlsheetveryhidden (which is equal to 2)
xlsheethidden (which is equal to 0)

Mike used False. In this case, Excel's VBA is forgiving and will see that as
0--the same as xlsheethidden.

======
And the code Mike suggested didn't actually do the save. You'd have to include
that if you really wanted it. But even if your code did the save or you forced
the user to do the save, the results might not be what you wanted.



Leanne wrote:

Hi Dave,

Thanks for pointing that out - I did not realise it would save it but it
makes sense that it would have to. I will take your advise and change it to
hide when opened.

Curiosity question again (only way I will learn!)

You have writen the code to hide differently that Mike (and what I had from
recording a macro). Is there any difference or is it simply preference?

"Dave Peterson" wrote:

I wouldn't hide the sheet when the workbook closes.

After your code hides it, your code will have to save the workbook. If the user
opened the workbook and destroyed 90% of the data and decides to close without
saving, your code just screwed up the workbook.

Instead, I'd hide the worksheet when the workbook opens.

Option Explicit
Sub Auto_Open()
thisworkbook.worksheets("Somesheetname").visible = xlsheethidden
end sub

You could use the workbook_open event if you wanted instead.

Leanne wrote:

I want a sheet to be hiden when the file is closed.

I have done the code to unhide it should the user require but because of
this I want it hiden again when the file is closed (if it has been unhiden)

Can any one tell me where/how I write this?

--

Dave Peterson


--

Dave Peterson