BeforeSave macro

  • Thread starter Thread starter Kiba
  • Start date Start date
K

Kiba

I get and error when i try to run a module named 'Merge' in the workbook
section before save.

Sub Workbook_BeforeSave()

Merge

End Sub

How can I make this work?
 
Kiba,

I see three possible problems:

1. "Merge" is an Excel reverved word, so it's not a good choice for a sub
or function name. Change the name from "Merge" to something else.
2. If it's really a module name, you can't "run" a module, so that might be
the problem in that case.
3. A Workbook_BeforeSave event really starts like this:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
The best way to create this event is to go into the ThisWorkbook module,
choose "Workbook" in the dropdown at the top left and choose the event in
the dropdown at the top right.

hth,

Doug
 
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call merge
End Sub

merge must be in a standard module.
 
Gary''s Student ,

"merge must be in a standard module."

Actually it can be in the ThisWorkbook module. Also, the OP doesn't need to
start using Call. For example, this code can all be in the ThisWorkbook
module:

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

Sub Test()
MsgBox "test"
End Sub

Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top