python与vba_萝卜头python:PYTHON 与VBA互调

1、python调用 VBA

假定我们的excel里边有个vba函数:foo,参数是args

其 VBA函数为

Sub test() 《============这个函数很重要,对应着python

Dim m

m = 1

Columns("G:G").Select

m = 1

On Error GoTo Err_Handle

For m = 1 To 65

Selection.Find(What:="男", After:=ActiveCell, LookIn:=xlFormulas, LookAt _

:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _

False, MatchByte:=False, SearchFormat:=False).Activate

ActiveCell.Replace What:="男", Replacement:="1", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

Next m

Exit Sub

Err_Handle:

End Sub

PYTHON 调用

必须另存为xlsm文件格式

2. 第二,在执行Python脚本的时候必须是打开excel的

3. 必须新

你可能感兴趣的:(python与vba)