10

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 
Community
  • 1
  • 1
CustomX
  • 9,948
  • 30
  • 85
  • 115
  • 2
    Have you put this code in the `ThisWorkbook` module? – chris neilsen Sep 11 '12 at 08:25
  • In the what? I'm sorry, this is all new. – CustomX Sep 11 '12 at 08:27
  • What is not working? What were you trying to do before save? – Passerby Sep 11 '12 at 08:29
  • Before the save I just called upon the macro. But I will be using this on a shared .xlsm file and because not all users will know how to use I want to "automate" it in this way. We make sure everyone saves after each line they edit, thus the macro is called. – CustomX Sep 11 '12 at 08:32

1 Answers1

25

Place your code in the ThisWorkbook module

Place your code here

brettdj
  • 54,857
  • 16
  • 114
  • 177
chris neilsen
  • 52,446
  • 10
  • 84
  • 123
  • 1
    Your Workbook_BeforeSave event may also not be executed when you are in Design mode, so make sure to exit Design mode before you save your workbook. – Oliver Hoffmann Jul 20 '16 at 09:18