Excel VBA - 保存前运行宏

时间:2012-09-11 08:11:53

标签: excel excel-vba vba

我一直在寻找如何在保存文档之前调用我的宏。我找到了这个,但是当我把代码放在里面时,它什么也没做。所以我认为我错过了一些东西。

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) 

Set shtVO = Sheets("Voice orders")
endRowVO = shtVO.Range("E" & Rows.Count).End(xlUp).Row

For Row = 11 To endRowVO
    If IsEmpty(shtVO.Cells(Row, 23).Value) = False Then
        If shtVO.Cells(Row, 3).Value <> shtVO.Cells(Row, 23) Then
            If shtVO.Cells(Row, 1).Value Like "*MIG*" Then
            Else
                shtVO.Cells(Row, 1).Value = shtVO.Cells(Row, 1).Value + "MIG"
            End If
        End If
    End If
Next Row

End Sub 

1 个答案:

答案 0 :(得分:23)

将您的代码放在ThisWorkbook模块

Place your code here