ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[¤À¨É] ¥ÎVBA©I¥spyhon°õ¦æ«ü¥O

[¤À¨É] ¥ÎVBA©I¥spyhon°õ¦æ«ü¥O

¥»©«³Ì«á¥Ñ white5168 ©ó 2012-5-6 23:21 ½s¿è

¬ÛÃöªºµ{¦¡½X¦p¤U, ¦³»Ý­n¤F¸Ñpython©Î°Q½×ªº¥i¥H¬Û¤¬¤Á½R
  1. Option Explicit '±j¨îÀɮפ¤ªº©Ò¦³ÅܼƳ£»Ý©ú½T«Å§i
½Æ»s¥N½X
  1. Sub ExcelVBACallPython1()
  2.     Dim PyScript : Set PyScript = CreateObject("MSScriptControl.ScriptControl") 'ª½±µ«Å§i¤@­Ó¨Ï¥Î Microsoft Script control 1.0ªºª«¥ó, ¨Ï¥ÎCreateObject¤è¦¡¥i¥H§K°£¦b "³]©w¤Þ¥Î¶µ¥Ø" ¤Ä¿ïMicrosoft Script control 1.0¶µ¥Ø
  3.     PyScript.Language = "python" '¿ï¾Ü©Ò­n¨Ï¥ÎªºScript»y¨¥,¥i¥H¨Ï¥ÎªºScript,¦pJavaScript, VBScript
  4.     PyScript.ExecuteStatement ("b=2+5*3") 'µ¹pythonªº°õ¦æ«ü¥O
  5.     MsgBox PyScript.Eval("b") 'Åã¥Ü­npythonªº°õ¦æ«ü¥Oªºµ²ªG
  6. End Sub
½Æ»s¥N½X
¤]¥i¥H¨Ï¥Î¥H¤Uªº¼gªk
  1. Sub ExcelVBACallPython2()
  2.     Dim PyScript: Set PyScript = CreateObject("MSScriptControl.ScriptControl") 'ª½±µ«Å§i¤@­Ó¨Ï¥Î Microsoft Script control 1.0ªºª«¥ó, ¨Ï¥ÎCreateObject¤è¦¡¥i¥H§K°£¦b "³]©w¤Þ¥Î¶µ¥Ø" ¤Ä¿ïMicrosoft Script control 1.0¶µ¥Ø
  3.     PyScript.Language = "python" '¿ï¾Ü©Ò­n¨Ï¥ÎªºScript»y¨¥,¥i¥H¨Ï¥ÎªºScript,¦pJavaScript, VBScript
  4.     MsgBox PyScript.Eval("2+5*3") 'Åã¥Ü­npythonªº°õ¦æ«ü¥Oªºµ²ªG
  5. End Sub
½Æ»s¥N½X
PS:¨­¬°Programmer¸Ó¦bµ{¦¡¤º¥[¤Wµù¸Ñ,¥H¤è«K¥¼¨Ó¦^ÀY½Æ²ß®É¥i¥H§Ö³t¤F¸Ñ,¤]Åý¨ä¥L¤H¥i¥H¶¶§Q¾Ç²ß,½Ð¾i¦¨¨}¦nµ{¦¡¼¶¼g®É¥[µù¸Ñªº²ßºD

        ÀR«ä¦Û¦b : ¡i»X½ªªº¦Û¥Ñ¡j¤H±`¦b¤°»ò³£¥i¥H¦Û¥Ñ¦Û¦bªº®É­Ô¡A«o³Q³oºØÀH¤ß©Ò±ýªº¦Û¥Ñ»X½ª¡AµêÂY®É¥ú¦Ó²@µLıª¾¡C
ªð¦^¦Cªí ¤W¤@¥DÃD