When I attempt to run the subsequent program code I get 'Run-time error 1004 Programmatic access to Visual Simple Project can be not trusted'. Does anyone know the environment to alter or way around that error?
Sub CréateButton
Dim 0bj As Item
Dim Program code As Thread
Bed sheets('Page1').Select
'create switch
Place Obj = ActiveSheet.OLEObjects.Add more(ClassType:='Forms.CommandButton.1',
Link:=False, DisplayAsIcon:=False, Left:=200, Top:=100, Width:=100, Height:=35)
Obj.Title = 'TestButton'
'buttonn text
ActiveSheet.OLEObjects(1).Item.Caption = 'Check Switch'
'macro text message
Code = 'Bass speaker ButtonTestClick' amp; vbCrLf
Program code = Code amp; 'Call Tester' amp; vbCrLf
Program code = Code amp; 'Finish Sub'
'include macro at the end of the piece component
With ActivéWorkbook.VBProject.VBComponents(ActivéSheet.Name).CodeModule
.insertlines.CountOfLines + 1, Code
End With
Finish Sub
Sub Tester
MsgBox 'You have got click on the check switch'
End Sub
This snippet shows how you can add VBA code to an Excel file at work period.
Click on Macro Settings Check ‘Trust Access to the VBA project object model’ (under Developer Macro Settings) Click OK to exit Trust Center window Then Click OK again to exit Excel Options window. When I try to run the following code I get Run-time error 1004 Programmatic access to Visual Basic Project is not trusted. Does anyone know.
Requirements
In this snippet I am using Microsoft Excel 2013 with the Microsoft Excel 15.0 item collection.
In this snippet I am using Microsoft Excel 2013 with the Microsoft Excel 15.0 item collection.
Before you can make use of this program code, you will have to modify a setting within Microsoft Excel to authorise the make use of of the VBA Task Object Model from external applications. This is a security feature to defend end customers from destructive programs and is usually disabled by default. If you perform not allow this function then the code below will result in an exception stating 'Programmatic access to Visual Fundamental Project is certainly not trusted' as quickly as you try to reference the VBA environment.
Enabling faith to the VBA Task Object Design
- Open Excel and access the Choices area.
- Choose the Put your trust in Center section
- Click the Confidence Center Configurations switch
- Select the Macro Configurations section
- Tick the package branded 'Have faith in access to the VBA project object magic size'
The code
You will require the following Imports statements:
You will require the following Imports statements:
Then:
526 Views
addcommentBecome the initial to answer