ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   BeforeSave macro (https://www.excelbanter.com/excel-programming/418650-beforesave-macro.html)

Kiba

BeforeSave macro
 
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?

Doug Glancy

BeforeSave macro
 
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

"Kiba" wrote in message
...
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?




Gary''s Student

BeforeSave macro
 
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 - gsnu200808


"Kiba" wrote:

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?


Doug Glancy

BeforeSave macro
 
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

"Gary''s Student" wrote in message
...
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 - gsnu200808


"Kiba" wrote:

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?





All times are GMT +1. The time now is 01:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com