Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA - Run macro before save

Tags:

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 
like image 555
CustomX Avatar asked Sep 11 '12 08:09

CustomX


1 Answers

Place your code in the ThisWorkbook module

Place your code here

like image 169
chris neilsen Avatar answered Oct 06 '22 15:10

chris neilsen