Stop macro if not in correct workseet

  • Thread starter Thread starter Patti
  • Start date Start date
P

Patti

A user will have a macro attached to a tool bar button. How can I ensure
that if they user is not in workbook "MyWorkbook" and not on sheet
"MyWorksheet" that the macro will not execute, instead giving MsgBox ("You
are not in the correct file")

Thanks in advance.

Patti
 
Hi
try something like
IF activeworkbook.name = "your workbookname" and _
activesheet.name = "your_worksheet_name" then
' continue
else
msgbox "Wrong workbook/worksheet"
exit sub
end if
 
That's perfect Frank. Thank you.

Patti


Frank Kabel said:
Hi
try something like
IF activeworkbook.name = "your workbookname" and _
activesheet.name = "your_worksheet_name" then
' continue
else
msgbox "Wrong workbook/worksheet"
exit sub
end if
 

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

Back
Top