0

我正在开发一个 excel/xlwings 工具来练习我的心算,使用我曾经在命令行下运行的旧 python 脚本。尝试运行我的 VBA 宏时,出现以下错误:


Traceback (most recent call last):
  File "<string>", line 1, in <module>

ModuleNotFoundError: No module named 'Training_factoring'

我将提供一些清单来为这个请求提供一些上下文:

  • 我正在使用 Anaconda3 和 spyder IDE
  • 我的 PYTHONPATH 是 C:\Users\benms\Anaconda3,我的解释器路径是 C:\Users\benms\Anaconda3\python.exe
  • 我的 excel 文件与我的 python 模块位于同一目录中
  • 我已经导入了 xlwings bas 文件
  • 我的 RunPython 调用确实遵循文档中的语法指南,并且我的 python 模块具有每个文档的 xw.Book.caller() 片段

这是我的代码示例:

VBA 宏

Sub PracticeStart()

Dim i As Integer
Dim Response As Long

    Do While True
        RunPython ("import Training_factoring; Training_factoring.DistributionTwoDigit()")

        Response = InputBox("Answer? ")
        ActiveWorkbook.Worksheets("practice").Range(i + 2, 1).Value = Response
        i = i + 2
    Loop

End Sub

Python 模块

def DistributionTwoDigit():
    wb = xw.Book.caller()
    x = random.randrange(10, 99, 1)
    y = random.randrange(10, 99, 1)
    i = 0

    i =+ 2
    wb.sheets[0].range("A1").value = "Distribution (Two-Digit)"
    wb.sheets[0].range(i+1,1).value = '{}*{}'.format(x, y)

    RunAnswer()
    wb.sheets[0].range(i+3,1).value = (x*y)

    wb.sheets[0].range(i+4,1).value = '-------------------------------'
    x = random.randrange(10, 90, 1)
    y = random.randrange(10, 90, 1)
4

0 回答 0