Macro to see if visual basic project is trusted?

Etter

New Member
Joined
Jan 11, 2004
Messages
2
I've been searching for a little while now and can't find exactly what I need.

I'm having a problem getting people to properly use a book I've made. It's a weekly schedule that creates daily schedules to be filled out later. The problem is that the main schedule exports a module and imports it into the new book. Now I know to check the trust visual basic box, but my scheduler does not. And after I leave I don't believe the people here will bother reading the instructions I made.

What I'd like to do it make a macro that first checks to see if visual basic is trusted or not. If it is trusted then it can go on to the exporting and importing. But if it is not then I need it to pop up a dialogue box telling the user how to fix the problem. I tried exporting a dummy module and on error while importing, popping up a messege box. But I am new with visual basic. I've got this far but I am scratching my head right now.

Can anyone point me in the right direction?

Thanks.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Etter

New Member
Joined
Jan 11, 2004
Messages
2
I guess I should have waited another hour before posting. This worked out fine.


Sub CreateDailyFilesCheckFirst()
' Check to see if viual basic is trusted
On Error Resume Next
ActiveWorkbook.VBProject.VBComponents("module3").Export ("c:\Ok to delete this.bas")
Application.VBE.ActiveVBProject.VBComponents.Import ("c:\Ok to delete this.bas")
If Err.Number <> 0 Then
MsgBox "Excel is not setup properly. You need to hit tools, macro, security. Select the Trusted Sources tab and check the box labeled Trust access to Visual Basic Project."
End If
If Err.Number = 0 Then CreateDailyFiles
Kill ("C:\Ok to delete this.bas")
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,821
Messages
5,772,464
Members
425,760
Latest member
paphon

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
Top