Excel VBA - 保存前运行宏 [英] Excel VBA - Run macro before save

查看:529
本文介绍了Excel VBA - 保存前运行宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been looking around on how to call my macro just before I save my document. I found this, but when I put my code inside it, it doesn't do anything. So I presume I'm missing something.

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 


推荐答案

将您的代码放在 ThisWorkbook 模块

这篇关于Excel VBA - 保存前运行宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆