Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JDH JDH is offline
external usenet poster
 
Posts: 13
Default Run macro with BeforeSave Event

Hi again,

I have a macro that I am running on a BeforeClose event and I need it to run
on a Workbook_BeforeSave event. When I click Save I receive an error message.
As of now I having to use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
mymarcro
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Run macro with BeforeSave Event

What's the code and where does it have an error.
--
HTH,
Barb Reinhardt



"JDH" wrote:

Hi again,

I have a macro that I am running on a BeforeClose event and I need it to run
on a Workbook_BeforeSave event. When I click Save I receive an error message.
As of now I having to use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
mymarcro
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
JDH JDH is offline
external usenet poster
 
Posts: 13
Default Run macro with BeforeSave Event

Macro is in "ThisWorkbook"

Private Sub Workbook_BeforeSave()
ThisWorkbook.Save
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Mold Release Verification\QSA Mold Release Verification.htm",
FileFormat _
:=xlHtml, ReadOnlyRecommended:=True, CreateBackup:=False
Application.DisplayAlerts = True
End Sub

Error message: Compile error - Precedure declaration dose not match or
procedure having the same name.

"Barb Reinhardt" wrote:

What's the code and where does it have an error.
--
HTH,
Barb Reinhardt



"JDH" wrote:

Hi again,

I have a macro that I am running on a BeforeClose event and I need it to run
on a Workbook_BeforeSave event. When I click Save I receive an error message.
As of now I having to use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
mymarcro
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Run macro with BeforeSave Event

Specifically what error message do you get? RunTime error? Compiler error?
What line of code is highlighted by the debugger when the error occurs?


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




"JDH" wrote in message
...
Hi again,

I have a macro that I am running on a BeforeClose event and I need it to
run
on a Workbook_BeforeSave event. When I click Save I receive an error
message.
As of now I having to use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
mymarcro
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Run macro with BeforeSave Event

The first line needs to look like this

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

And you need to do some other checking, but I don't have time to help with
that part. I've got a fire of my own to put out. :) Hopefully someone
else can assist.
--
HTH,
Barb Reinhardt



"JDH" wrote:

Macro is in "ThisWorkbook"

Private Sub Workbook_BeforeSave()
ThisWorkbook.Save
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Mold Release Verification\QSA Mold Release Verification.htm",
FileFormat _
:=xlHtml, ReadOnlyRecommended:=True, CreateBackup:=False
Application.DisplayAlerts = True
End Sub

Error message: Compile error - Precedure declaration dose not match or
procedure having the same name.

"Barb Reinhardt" wrote:

What's the code and where does it have an error.
--
HTH,
Barb Reinhardt



"JDH" wrote:

Hi again,

I have a macro that I am running on a BeforeClose event and I need it to run
on a Workbook_BeforeSave event. When I click Save I receive an error message.
As of now I having to use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
mymarcro
End Sub




  #6   Report Post  
Posted to microsoft.public.excel.programming
JDH JDH is offline
external usenet poster
 
Posts: 13
Default Run macro with BeforeSave Event

It is in "ThisWorkbook" module

When I use: "Private Sub Workbook_BeforeSave()"

Error message: Compile error - Precedure declaration dose not match or
procedure having the same name.


When I use: "Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,
Cancel As Boolean)"

I receive a message "Microsoft Excel for windows has encountered a problem
and needs to close.

"Chip Pearson" wrote:

Specifically what error message do you get? RunTime error? Compiler error?
What line of code is highlighted by the debugger when the error occurs?


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




"JDH" wrote in message
...
Hi again,

I have a macro that I am running on a BeforeClose event and I need it to
run
on a Workbook_BeforeSave event. When I click Save I receive an error
message.
As of now I having to use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
mymarcro
End Sub




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Run macro with BeforeSave Event

When I step through your code, it appears to go into an infinite loop. Every
time you save, it goes back through the Workbook_BeforeSave event. You may
need to add

Application.Enableevents = FALSE

at the beginning of your code and

Application.Enableevents = TRUE

at the end of your code
--
HTH,
Barb Reinhardt



"JDH" wrote:

Macro is in "ThisWorkbook"

Private Sub Workbook_BeforeSave()
ThisWorkbook.Save
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Mold Release Verification\QSA Mold Release Verification.htm",
FileFormat _
:=xlHtml, ReadOnlyRecommended:=True, CreateBackup:=False
Application.DisplayAlerts = True
End Sub

Error message: Compile error - Precedure declaration dose not match or
procedure having the same name.

"Barb Reinhardt" wrote:

What's the code and where does it have an error.
--
HTH,
Barb Reinhardt



"JDH" wrote:

Hi again,

I have a macro that I am running on a BeforeClose event and I need it to run
on a Workbook_BeforeSave event. When I click Save I receive an error message.
As of now I having to use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
mymarcro
End Sub


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Run macro with BeforeSave Event

Just looking at the code real quick, it looks to me that the first line in
the sub is going to cause a problem:

ThisWorkbook.Save

This event is being called because the file is about to be saved, so after
it runs the file will save and that line is unnecessary. I would also think,
and I could be wrong, but if before it saves it runs this sub, when you try
to save it, it wants to run through it again.

Just my quick thoughts. Hope it helps.

"JDH" wrote:

It is in "ThisWorkbook" module

When I use: "Private Sub Workbook_BeforeSave()"

Error message: Compile error - Precedure declaration dose not match or
procedure having the same name.


When I use: "Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,
Cancel As Boolean)"

I receive a message "Microsoft Excel for windows has encountered a problem
and needs to close.

"Chip Pearson" wrote:

Specifically what error message do you get? RunTime error? Compiler error?
What line of code is highlighted by the debugger when the error occurs?


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




"JDH" wrote in message
...
Hi again,

I have a macro that I am running on a BeforeClose event and I need it to
run
on a Workbook_BeforeSave event. When I click Save I receive an error
message.
As of now I having to use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
mymarcro
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I change a Worksheet_change event to a beforesave event? Tueanker Excel Programming 5 June 29th 07 03:00 PM
Need help with BeforeSave event Chuck M Excel Programming 4 March 6th 07 02:15 PM
Trying to run macro on the BeforeSave event dmagoo22 Excel Programming 3 July 5th 06 09:38 PM
BeforeSave event Carl Bowman Excel Discussion (Misc queries) 4 February 6th 05 12:28 PM
BeforeSave event j23 Excel Programming 0 April 6th 04 11:15 AM


All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"