I am working on an excel sheet for some not-so-excel-savvy users. They are using varying versions of excel and I need to make sure they all have the correct reference libraries to run the macros. I plan to use the VBE object and set references to the library GUIDs. That way it would set the correct library no matter the version if it is missing. I was tinkering with the idea of using the SendKeys method to gain programming access to the VBE - with user consent of course! The code could then check for the required libraries at startup, then turn back off programming access to the VBE. I have figured out how to enable the access with SendKeys, but it will not acknowledge the granted access until the sub is finished and re-run. Is there a way to get VB to recognize the granted access while still in the sub? The main problem is the Calendar Control library. VB will not even allow the workbook to use macros at all if there is an error here. So i can't end the sub and have the user click something to re-initiate it. I've got to knock it out in round 1. Here is my code, any suggestions?
It's hard to test it on my end because, well, the excel sheet works for me. If I unlink the libraries it just comes off with a Object with Block Variable Not Set error. For them it wont even compile.
-JTBorton
Another Day, Another Disaster
Code:
Sub CheckVBE_Libraries()
Dim AltKey As String
Dim CtrlKey As String
Dim ShiftKey As String
Dim TabKey As String
Dim EnterKey As String
CheckVBE:
On Error Resume Next
With Application.VBE
[highlight]If Err.Number = 1004 Then:[/highlight] GoTo TurnOnVBETrust
[b][COLOR=red]Here it continually throws an error even after enabling VBE programming access [/color][/b]
On Error GoTo 0
'(DO STUFF HERE)
End With
Exit Sub
TurnOnVBETrust:
'--------------------------
AltKey = "%"
CtrlKey = "^"
ShiftKey = "+"
TabKey = "{TAB}"
EnterKey = "~"
'--------------------------
SendKeys AltKey & "T", False
'- delay 1 second
Application.Wait Now + TimeValue("00:00:01")
SendKeys "M", False
SendKeys "S", False
'- delay 1 second
Application.Wait Now + TimeValue("00:00:01")
SendKeys "T", False
SendKeys AltKey & "V", False
SendKeys "S", False
SendKeys EnterKey
GoTo CheckVBE
End Sub
It's hard to test it on my end because, well, the excel sheet works for me. If I unlink the libraries it just comes off with a Object with Block Variable Not Set error. For them it wont even compile.
-JTBorton
Another Day, Another Disaster