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.
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

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
 

Watch MrExcel Video

Forum statistics

Threads
1,111,910
Messages
5,541,541
Members
410,547
Latest member
htran4
Top