Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用xlwings通过Python运行Excel宏_Python_Excel_Vba_Xlwings - Fatal编程技术网

无法使用xlwings通过Python运行Excel宏

无法使用xlwings通过Python运行Excel宏,python,excel,vba,xlwings,Python,Excel,Vba,Xlwings,我试图通过Python使用xlwings运行简单的Excel宏,但它不起作用 我尝试在JupyterLab中运行Python。VBA和Python这两种代码都非常简单,当我在Excel中运行VBA代码时,它工作正常。此外,我还尝试了一些使用xlwings的简单python代码,如 将xlwings作为xw导入 wb=xw.Book('test.xlsm') 工作表=工作表工作表[0] 表.范围('A1')。值='test' 工作正常 macro = wb.macro('ThisWorkbook

我试图通过Python使用xlwings运行简单的Excel宏,但它不起作用

我尝试在JupyterLab中运行Python。VBA和Python这两种代码都非常简单,当我在Excel中运行VBA代码时,它工作正常。此外,我还尝试了一些使用xlwings的简单python代码,如

将xlwings作为xw导入
wb=xw.Book('test.xlsm')
工作表=工作表工作表[0]
表.范围('A1')。值='test'
工作正常

macro = wb.macro('ThisWorkbook.test')
但是,下面的python代码不起作用

将xlwings作为xw导入
wb=xw.Book('test.xlsm')
宏=wb.macro(“测试”)
宏()
我将下面的VBA代码放在ExcelVBA编辑器的“ThisWorkbook”上

Sub test()
    Range("A1").Value = "This is a test."
End Sub
错误消息如下所示

com_error: "Cannot run the macro 'test.xlsm'!test'. The macro may not be available in this workbook or all macros may be disabled."
我自己解决了

我像这样编辑代码,它工作正常

macro = wb.macro('ThisWorkbook.test')
我自己解决了

我像这样编辑代码,它工作正常

macro = wb.macro('ThisWorkbook.test')