ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   run macro before closing if worksheet name is fixed (https://www.excelbanter.com/excel-programming/433304-run-macro-before-closing-if-worksheet-name-fixed.html)

Jaan

run macro before closing if worksheet name is fixed
 
Hi All

How can I create macro if worksheet name is ex."Template" before closing
workbook? I use this sheetname in more then ten workbooks

Best regards



Mike Fogleman[_2_]

run macro before closing if worksheet name is fixed
 
If you are asking how to refer to a worksheet with the same name in several
different workbooks, then you would include the workbook name also:

Workbooks ("MyBook").Worksheets ("Template")
Workbooks ("MyBook2").Worksheets ("Template")
Workbooks ("MyBook3").Worksheets ("Template")
etc...
Mike F
"Jaan" wrote in message
...
Hi All

How can I create macro if worksheet name is ex."Template" before closing
workbook? I use this sheetname in more then ten workbooks

Best regards





Simon Lloyd[_1244_]

run macro before closing if worksheet name is fixed
 

Do you want to check if the activesheet is called "Template" and if it
is close the workbook? if so,
Code:
--------------------
If ActiveWorkbook.ActiveSheet.Name = "Template" Then
ActiveWorkbook.Close False
End If
--------------------
Jaan;478879 Wrote:
Hi All

How can I create macro if worksheet name is ex."Template" before
closing
workbook? I use this sheetname in more then ten workbooks

Best regards



--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=132083


Jaan

run macro before closing if worksheet name is fixed
 
Hi Simon
I want to check all my workbooks. If the workbook what i will close contain
sheet "Template", then must run "MyMacro".The Mike solution is not this what
I want, because I create severel workbooks every day with worksheet
"Template".
As many I get the picture, this solution need rewrite macro each time I will
create new workbook

Best regards


"Simon Lloyd" kirjutas:


Do you want to check if the activesheet is called "Template" and if it
is close the workbook? if so,
Code:
--------------------
If ActiveWorkbook.ActiveSheet.Name = "Template" Then
ActiveWorkbook.Close False
End If
--------------------
Jaan;478879 Wrote:
Hi All

How can I create macro if worksheet name is ex."Template" before
closing
workbook? I use this sheetname in more then ten workbooks

Best regards



--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=132083




All times are GMT +1. The time now is 12:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com