The problem is that to pass quotation marks inside quotes is necessary to escape them first, or this will not work because it will cause a syntax error:
Dim str
str = "MsgBox "Olá mundo""
Execute(str)
In VB it is necessary to pass a quotation mark in front of each asp you want to escape, like this:
Dim str
str = "MsgBox ""Olá mundo"""
Execute(str)
Note that to apply the quotation marks inside the string it was necessary to transform this:
"Olá mundo"
In:
""Olá mundo""
This is the escape of the quotes.
The use of Execute
Gabriel already showed in a .vbs seems to work normal, in office "macros" I do not know how it behaves, however as an alternative it has this SOen suggestion: link (an example in Excel)
Sub StringExecute(strToExecute As String)
Dim vbComp As Object
Set vbComp = ThisWorkbook.VBProject.VBComponents.Add(1)
vbComp.CodeModule.AddFromString "Sub foo()" & vbCrLf & strToExecute & vbCrLf & "End Sub"
Application.Run vbComp.name & ".foo"
ThisWorkbook.VBProject.VBComponents.Remove vbComp
End Sub
Sub Testing()
StringExecute "MsgBox ""Olá mundo"""
End Sub