Public Sub test99()
On Error GoTo Catch
a1 = ThisWorkbook.VBProject.VBComponents.Count
Exit Sub
Catch:
If Not Err.Number = 1004 Then Exit Sub
a2 = MsgBox("A macro failure has occurred." & Chr(10) & Chr(10) & _
"Visual Basic Project ""Trust"" may be disabled." & Chr(10) & _
"To enable this setting:" & Chr(10) & Chr(10) & _
"1) Click " & Chr(145) & "Tools-> Macro-> Security" & Chr(146) & Chr(10) & _
"2) Click Trusted Publishers" & Chr(10) & _
"3) Check Trust Access to Visual Basic Project", vbOKOnly, "Runtime Error 1004")
End Sub
If VBAIsTrusted = False Then
Call SendKeys("%TM{DOWN}{DOWN}{ENTER}T%V{ENTER}")
DoEvents
Application.Wait Now + TimeValue("00:00:05")
End If
'Put your code here.
If VBAIsTrusted = True Then
Call SendKeys("%TM{DOWN}{DOWN}{ENTER}T%V{ENTER}")
DoEvents
Application.Wait Now + TimeValue("00:00:05")
End If
Do: ThisWorkbook.VBProject.VBComponents.Count: Resume: _
Loop While Err.Number <> 0
Private Function VBAIsTrusted() As Boolean
On Error GoTo Label1
a1 = ThisWorkbook.VBProject.VBComponents.Count
VBAIsTrusted = True
Label1:
VBAIsTrusted = False
End Function
Public Sub CheckTrust()
On Error Resume Next
If VBAIsTrusted = False Then
Call SendKeys("%TM{DOWN}{DOWN}{ENTER}T%V{ENTER}")
DoEvents
Do: Resume: ThisWorkbook.VBProject.VBComponents.Count: _
Loop While Err.Number <> 0
End If
MsgBox ThisWorkbook.VBProject.VBComponents.Count
If VBAIsTrusted = True Then
Call SendKeys("%TM{DOWN}{DOWN}{ENTER}T%V{ENTER}")
DoEvents
Do: Resume: ThisWorkbook.VBProject.VBComponents.Count: _
Loop While Err.Number <> 0
End If
End Sub
Private Function VBAIsTrusted() As Boolean
On Error GoTo Label1
a1 = ThisWorkbook.VBProject.VBComponents.Count
VBAIsTrusted = True
Label1:
VBAIsTrusted = False
End Function
Public Sub CheckTrust()
On Error Resume Next
If VBAIsTrusted = False Then
Call SendKeys("%TM{DOWN}{DOWN}{ENTER}T%V{ENTER}")
Do
b1 = ThisWorkbook.VBProject.VBComponents.Count
DoEvents
Loop While IsEmpty(b1)
End If
MsgBox ThisWorkbook.VBProject.VBComponents.Count
If VBAIsTrusted = True Then
Call SendKeys("%TM{DOWN}{DOWN}{ENTER}T%V{ENTER}")
Do
b1 = ThisWorkbook.VBProject.VBComponents.Count
DoEvents
Loop While Not IsEmpty(b1)
End If
End Sub
Loop Until IsEmpty(b1)
Do
i = i + 1
Loop Until i = 10
MsgBox i
<code>[COLOR=#000000]MsgBox IIf[/COLOR][COLOR=#000000]([/COLOR]</code>VBAIsTrusted = False<code>[COLOR=#990000][/COLOR][COLOR=#000000], [/COLOR][COLOR=#2a00ff]"UnLocked"[/COLOR][COLOR=#000000], [/COLOR][COLOR=#2a00ff]"Locked"[/COLOR][COLOR=#000000])[/COLOR]</code>