Startup Macro and Security Check

fchepote

New Member
Joined
Mar 22, 2004
Messages
1
Hi everybody!

For the past few days I have been banging my head against my computer screen, as my VB programming skills are almost like my parent's. I want to write a macro that startups with the excel Worksheet and checks for a certain file to be in certain location (to avoid mass distribution of the file). If the file is not there, a dialog box appears saying "You are not allowed to use this file" (or whatever text) and closes the workbook. Can anybody help me out?

* It has to be a startup macro

* It has to be enabled to make the worksheet visible. If the macro is turned off, the worksheet should close or not be visible

* It must check a certain file is in the hard drive (for example: c:\windows\system32\msmmpi2.sys)

* When the worksheet is saved, the macro must be saved with it.

Thank you very much

-Felipe Chepote
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome to the Board!

The following code requires you to have a sheet called "Notification". On that sheet you need to put a message to your users that they must enable macros. The code goes in the ThisWorkbook module. Change the path to suit.

<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet

<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Open()
    <SPAN style="color:#00007F">If</SPAN> ActiveWorkbook.FullName <> _
        "C:\Documents and Settings\All Users\Desktop\Force Macro Enable.xls" _
    <SPAN style="color:#00007F">Then</SPAN>
        MsgBox "You are not authorized to view this workbook."
        ActiveWorkbook.Close <SPAN style="color:#00007F">False</SPAN>
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> ActiveWorkbook.Worksheets
        <SPAN style="color:#00007F">If</SPAN> ws.Name <> "Notification" <SPAN style="color:#00007F">Then</SPAN>
            ws.Visible = <SPAN style="color:#00007F">True</SPAN>
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">Next</SPAN> ws
    
    Sheets("Notification").Visible = xlVeryHidden

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_BeforeClose(Cancel <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>)
    Sheets("Notification").Visible = <SPAN style="color:#00007F">True</SPAN>
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> ActiveWorkbook.Worksheets
        <SPAN style="color:#00007F">If</SPAN> ws.Name <> "Notification" <SPAN style="color:#00007F">Then</SPAN>
            ws.Visible = xlVeryHidden
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">Next</SPAN> ws
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,

Smitty

EDIT: Left out a snippet
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,305
Members
449,150
Latest member
NyDarR

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top