Last active
March 10, 2019 12:18
-
-
Save ezhov-da/888c4ae413728345b3991f5494f4cb81 to your computer and use it in GitHub Desktop.
vba выполнение кода из строки
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Надо в VBA с помощью меню Tools/References подключить библиотеку "Microsoft Script Control 1.0", а затем сделать следующее: | |
Sub ScripCode() | |
Dim first As Integer | |
Dim second As Integer | |
first = 12 | |
second = 17 | |
Dim resultUsual As Integer | |
Dim resultFromCode As Integer | |
resultUsual = (first + first / second * second - first * first) / second | |
Debug.Print resultUsual | |
Dim sс As New MSScriptControl.ScriptControl | |
sс.Language = "VBScript" ' Инициализация | |
Dim text As String | |
text = "(:first + :first / :second * :second - :first * :first) / :second" | |
text = Replace(text, ":first", first) | |
text = Replace(text, ":second", second) | |
resultFromCode = sс.Eval(text) | |
Set sс = Nothing ' Деинициализация | |
Debug.Print resultFromCode | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment