Enable Trust Access to VBA Object Model through SendKeys Excel Spanish version (1 Viewer)

Mohsin Malik

Registered User.
Local time
Tomorrow, 02:34
Joined
Mar 25, 2012
Messages
175
I am working on excel file that enabled VBA Object Model Through SendKeys for all English language users, SendKeys are not working for Users with Office Spanish version. I am hoping if anyone help in translating SendKeys to spanish version? I have placed my code snippets below.

Code:
Public Sub EnableTrustAccess()
Dim i As Integer
Dim strkeys As String
On Error Resume Next
    Do While i <= 2 'try to sendkeys 3 times
    DoEvents
        Sleep 100
    DoEvents
        If Application.LanguageSettings.LanguageID(msoLanguageIDUI) = 1033 Then 'English Version
            strkeys = "%tms%v{ENTER}" 'Enable trust access to vba project object model
        Else 'Spanish Version
            strkeys = "????"     'enable trust access to vba project object model
        End If
        
        Call SendKeys(Trim(strkeys)) 
        DoEvents
        Sleep (100)
        i = i + 1
    Loop
End Sub
 

isladogs

MVP / VIP
Local time
Today, 22:34
Joined
Jan 14, 2017
Messages
18,186
First of all, your If ... Else logic may be flawed in that the Else section will apply to any non-English version such as French /German etc.
Presumably from your post, those would also have different SendKeys actions for this task

So this would be better:
Code:
If
 'English code
ElseIf
'Spanish code
Else
'other languages - possibly omit this part
end if

However, using SendKeys is NOT recommended as key combinations that work in one version may not work in another version.

I think you've inadvertantly given another reason for not using SendKeys in that it appears the key settings differ between languages!

I had to test your Send Keys combination to find out exactly what they did ...
File...Options ...Trust Center ...Macro Settings then check 'Trust access to the VBA project object model'

If you MUST use them, then in a Spanish version of Excel, go through those steps looking for the underlined letter for each step.
I've highlighted them in RED above

However, you would be far better doing a Google search for 'Enable VBA object model using code'.
Here are the first 2 links I found using that:
https://blogs.msdn.microsoft.com/cristib/2012/02/29/vba-how-to-programmatically-enable-access-to-the-vba-object-model-using-macros/
http://www.darinhiggins.com/dynamically-enabling-access-to-the-vba-object-model-in-office-apps/

Hopefully one of those will give you universal code that will apply no matter what language version is in use.
If neither of those links helps, there are plenty of other search results
 

Users who are viewing this thread

Top Bottom