¥»©«³Ì«á¥Ñ white5168 ©ó 2012-5-6 23:21 ½s¿è
¬ÛÃöªºµ{¦¡½X¦p¤U, ¦³»Ýn¤F¸Ñpython©Î°Q½×ªº¥i¥H¬Û¤¬¤Á½R- Option Explicit '±j¨îÀɮפ¤ªº©Ò¦³ÅܼƳ£»Ý©ú½T«Å§i
½Æ»s¥N½X- Sub ExcelVBACallPython1()
- Dim PyScript : Set PyScript = CreateObject("MSScriptControl.ScriptControl") 'ª½±µ«Å§i¤@ӨϥΠMicrosoft Script control 1.0ªºª«¥ó, ¨Ï¥ÎCreateObject¤è¦¡¥i¥H§K°£¦b "³]©w¤Þ¥Î¶µ¥Ø" ¤Ä¿ïMicrosoft Script control 1.0¶µ¥Ø
- PyScript.Language = "python" '¿ï¾Ü©Òn¨Ï¥ÎªºScript»y¨¥,¥i¥H¨Ï¥ÎªºScript,¦pJavaScript, VBScript
- PyScript.ExecuteStatement ("b=2+5*3") 'µ¹pythonªº°õ¦æ«ü¥O
- MsgBox PyScript.Eval("b") 'Åã¥Ünpythonªº°õ¦æ«ü¥Oªºµ²ªG
- End Sub
½Æ»s¥N½X ¤]¥i¥H¨Ï¥Î¥H¤Uªº¼gªk- Sub ExcelVBACallPython2()
- Dim PyScript: Set PyScript = CreateObject("MSScriptControl.ScriptControl") 'ª½±µ«Å§i¤@ӨϥΠMicrosoft Script control 1.0ªºª«¥ó, ¨Ï¥ÎCreateObject¤è¦¡¥i¥H§K°£¦b "³]©w¤Þ¥Î¶µ¥Ø" ¤Ä¿ïMicrosoft Script control 1.0¶µ¥Ø
- PyScript.Language = "python" '¿ï¾Ü©Òn¨Ï¥ÎªºScript»y¨¥,¥i¥H¨Ï¥ÎªºScript,¦pJavaScript, VBScript
- MsgBox PyScript.Eval("2+5*3") 'Åã¥Ünpythonªº°õ¦æ«ü¥Oªºµ²ªG
- 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 |