2012-09-11 20 views
7

Ich habe mich gerade gefragt, wie ich mein Makro aufrufen soll, bevor ich mein Dokument speichere. Ich habe das gefunden, aber wenn ich meinen Code hineinlege, macht das nichts. Also vermute ich, dass ich etwas verpasse.Excel VBA - Makro vor dem Speichern ausführen

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

Sie diesen Code setzen Wurden im 'ThisWorkbook' Modul? –

+0

In was? Es tut mir leid, das ist alles neu. – CustomX

+0

Was funktioniert nicht? Was hast du vor dem Speichern versucht? – Passerby

Antwort

20

Platz Code im ThisWorkbook Modul

Place your code here

+0

Ihr Workbook_BeforeSave-Ereignis wird möglicherweise auch nicht ausgeführt, wenn Sie sich im Entwurfsmodus befinden. Stellen Sie daher sicher, dass Sie den Entwurfsmodus beenden, bevor Sie Ihre Arbeitsmappe speichern. –

Verwandte Themen