![]() |
exclusive macros
Can a macro be made so that it will only work in the workbook it
belongs to? |
exclusive macros
You Could Try somthing like... Function IsWorkbook() As Boolean IsWorkbook = ActiveWorkbook.Name = ("Book2") End Function Sub Test() If IsWorkbook = True Then MsgBox "Your Macro Here" Else MsgBox "Sorry no Macro for you" End If End Sub "Fan924" wrote: Can a macro be made so that it will only work in the workbook it belongs to? |
exclusive macros
Thanks, I will try this.
|
exclusive macros
Depends on what your macro does, you can refer to objects in the workbook by using ThisWorkBook, e.g. Code: -------------------- With ThisWorkbook .Sheets(1).UsedRange.Copy .Sheets(2) End With -------------------- Or Code: -------------------- If Not ActiveWorkbook.Name = ThisWorkbook.Name Then Exit Sub 'your code here -------------------- -- royUK Hope that helps, RoyUK For tips & examples visit my 'web site' (http://www.excel-it.com/) ------------------------------------------------------------------------ royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=38704 |
exclusive macros
Function IsWorkbook() As Boolean
IsWorkbook = ActiveWorkbook.Name = ("Book2") End Function Sub Test() If IsWorkbook = True Then MsgBox "Your Macro Here" Else MsgBox "Sorry no Macro for you" End If End Sub I could not get this to work, Thanks to Chip Pearson's timely post, I made a few changes to it and it worked. If ThisWorkbook.FullName = ActiveWorkbook.FullName Then MsgBox "Your Macro Here" Else MsgBox "Sorry no Macro for you" End If |
All times are GMT +1. The time now is 12:38 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com