Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tjh tjh is offline
external usenet poster
 
Posts: 96
Default Before Save w Addin

Hello,

I am trying to use an add-in, which will perform an action before saving to
the workbook. The before save event worked when I was using it as a normal
excel workbook, however when I changed it to an Add-in ---- the event does
not seem to work the same.

I am using an add-in because I would like this code to run anytime I save an
excel file.

Within the add-in I have the code to start the process in the VBAProject
"ThisWorkbook" using the BeforeSave event.

Any suggestions on getting this to run before any excel file is saved.

Thank You,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Before Save w Addin

The problem is that you are not saving the addin so the code does not fire.
To do waht you want is a bit more complicated. Here is some code...

In a new Class module name clsXLEvents
Option Explicit
Private WithEvents xlApp As Excel.Application

Private Sub Class_Initialize()
Set xlApp = Excel.Application
End Sub

Private Sub xlApp_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox "Tada"
End Sub

In a standard module named whatever
Option Explicit

Public xlApp As clsXLEvents

And in ThisWorkbook
Option Explicit

Private Sub Workbook_AddinInstall()
Set xlApp = New clsXLEvents
End Sub

Private Sub Workbook_AddinUninstall()
Set xlApp = Nothing
End Sub

Private Sub Workbook_Open()
Set xlApp = New clsXLEvents
End Sub

That should do what you want it to do...

--
HTH...

Jim Thomlinson


"tjh" wrote:

Hello,

I am trying to use an add-in, which will perform an action before saving to
the workbook. The before save event worked when I was using it as a normal
excel workbook, however when I changed it to an Add-in ---- the event does
not seem to work the same.

I am using an add-in because I would like this code to run anytime I save an
excel file.

Within the add-in I have the code to start the process in the VBAProject
"ThisWorkbook" using the BeforeSave event.

Any suggestions on getting this to run before any excel file is saved.

Thank You,

  #3   Report Post  
Posted to microsoft.public.excel.programming
tjh tjh is offline
external usenet poster
 
Posts: 96
Default Before Save w Addin

Thank you for your response,

This seems to work the first time that I click the save button, but if I
click the save button more than once while a workbook or workbook session is
open, the code does not run.
It appears that the problem is when we --- Set xlApp = New clsXLEvents
which is done when a workbook is opened or the addin is installed.

What would you suggest to be an appropriate event to allow for the setup,
which would allow for multiple saves.

Thank You,


"Jim Thomlinson" wrote:

The problem is that you are not saving the addin so the code does not fire.
To do waht you want is a bit more complicated. Here is some code...

In a new Class module name clsXLEvents
Option Explicit
Private WithEvents xlApp As Excel.Application

Private Sub Class_Initialize()
Set xlApp = Excel.Application
End Sub

Private Sub xlApp_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox "Tada"
End Sub

In a standard module named whatever
Option Explicit

Public xlApp As clsXLEvents

And in ThisWorkbook
Option Explicit

Private Sub Workbook_AddinInstall()
Set xlApp = New clsXLEvents
End Sub

Private Sub Workbook_AddinUninstall()
Set xlApp = Nothing
End Sub

Private Sub Workbook_Open()
Set xlApp = New clsXLEvents
End Sub

That should do what you want it to do...

--
HTH...

Jim Thomlinson


"tjh" wrote:

Hello,

I am trying to use an add-in, which will perform an action before saving to
the workbook. The before save event worked when I was using it as a normal
excel workbook, however when I changed it to an Add-in ---- the event does
not seem to work the same.

I am using an add-in because I would like this code to run anytime I save an
excel file.

Within the add-in I have the code to start the process in the VBAProject
"ThisWorkbook" using the BeforeSave event.

Any suggestions on getting this to run before any excel file is saved.

Thank You,

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Before Save w Addin

All of the code that I gave you should be in your addin. It instatiates an
instance of Excel that "Listens" for events. When it detects an event (Before
Save) then it performs it's action. It has nothing to do with how often a
file is saved or such. The class is instanitated only once and the instance
persist for the duration of the Excel session.
--
HTH...

Jim Thomlinson


"tjh" wrote:

Thank you for your response,

This seems to work the first time that I click the save button, but if I
click the save button more than once while a workbook or workbook session is
open, the code does not run.
It appears that the problem is when we --- Set xlApp = New clsXLEvents
which is done when a workbook is opened or the addin is installed.

What would you suggest to be an appropriate event to allow for the setup,
which would allow for multiple saves.

Thank You,


"Jim Thomlinson" wrote:

The problem is that you are not saving the addin so the code does not fire.
To do waht you want is a bit more complicated. Here is some code...

In a new Class module name clsXLEvents
Option Explicit
Private WithEvents xlApp As Excel.Application

Private Sub Class_Initialize()
Set xlApp = Excel.Application
End Sub

Private Sub xlApp_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox "Tada"
End Sub

In a standard module named whatever
Option Explicit

Public xlApp As clsXLEvents

And in ThisWorkbook
Option Explicit

Private Sub Workbook_AddinInstall()
Set xlApp = New clsXLEvents
End Sub

Private Sub Workbook_AddinUninstall()
Set xlApp = Nothing
End Sub

Private Sub Workbook_Open()
Set xlApp = New clsXLEvents
End Sub

That should do what you want it to do...

--
HTH...

Jim Thomlinson


"tjh" wrote:

Hello,

I am trying to use an add-in, which will perform an action before saving to
the workbook. The before save event worked when I was using it as a normal
excel workbook, however when I changed it to an Add-in ---- the event does
not seem to work the same.

I am using an add-in because I would like this code to run anytime I save an
excel file.

Within the add-in I have the code to start the process in the VBAProject
"ThisWorkbook" using the BeforeSave event.

Any suggestions on getting this to run before any excel file is saved.

Thank You,

  #5   Report Post  
Posted to microsoft.public.excel.programming
tjh tjh is offline
external usenet poster
 
Posts: 96
Default Before Save w Addin

Your code works using the Message Box.

The problem I think is with my additional code. Instead of using your
message box, I placed in the section containing the BeforeSave event a

Userform1.Show

This opens a form which will as a couple of questions with various answers,
from here the code will perform an action before the save. I think my
userform is causing the problem.

Should this cause a different outcome than your code?? Or any thoughts as to
why my userform will not appear after the second, third, fourth.... time I
save?

Thank You,




"Jim Thomlinson" wrote:

All of the code that I gave you should be in your addin. It instatiates an
instance of Excel that "Listens" for events. When it detects an event (Before
Save) then it performs it's action. It has nothing to do with how often a
file is saved or such. The class is instanitated only once and the instance
persist for the duration of the Excel session.
--
HTH...

Jim Thomlinson


"tjh" wrote:

Thank you for your response,

This seems to work the first time that I click the save button, but if I
click the save button more than once while a workbook or workbook session is
open, the code does not run.
It appears that the problem is when we --- Set xlApp = New clsXLEvents
which is done when a workbook is opened or the addin is installed.

What would you suggest to be an appropriate event to allow for the setup,
which would allow for multiple saves.

Thank You,


"Jim Thomlinson" wrote:

The problem is that you are not saving the addin so the code does not fire.
To do waht you want is a bit more complicated. Here is some code...

In a new Class module name clsXLEvents
Option Explicit
Private WithEvents xlApp As Excel.Application

Private Sub Class_Initialize()
Set xlApp = Excel.Application
End Sub

Private Sub xlApp_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox "Tada"
End Sub

In a standard module named whatever
Option Explicit

Public xlApp As clsXLEvents

And in ThisWorkbook
Option Explicit

Private Sub Workbook_AddinInstall()
Set xlApp = New clsXLEvents
End Sub

Private Sub Workbook_AddinUninstall()
Set xlApp = Nothing
End Sub

Private Sub Workbook_Open()
Set xlApp = New clsXLEvents
End Sub

That should do what you want it to do...

--
HTH...

Jim Thomlinson


"tjh" wrote:

Hello,

I am trying to use an add-in, which will perform an action before saving to
the workbook. The before save event worked when I was using it as a normal
excel workbook, however when I changed it to an Add-in ---- the event does
not seem to work the same.

I am using an add-in because I would like this code to run anytime I save an
excel file.

Within the add-in I have the code to start the process in the VBAProject
"ThisWorkbook" using the BeforeSave event.

Any suggestions on getting this to run before any excel file is saved.

Thank You,



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Before Save w Addin

I can not tell without seeing more code... I am gone for the day so I can't
help you until tomorrow...
--
HTH...

Jim Thomlinson


"tjh" wrote:

Your code works using the Message Box.

The problem I think is with my additional code. Instead of using your
message box, I placed in the section containing the BeforeSave event a

Userform1.Show

This opens a form which will as a couple of questions with various answers,
from here the code will perform an action before the save. I think my
userform is causing the problem.

Should this cause a different outcome than your code?? Or any thoughts as to
why my userform will not appear after the second, third, fourth.... time I
save?

Thank You,




"Jim Thomlinson" wrote:

All of the code that I gave you should be in your addin. It instatiates an
instance of Excel that "Listens" for events. When it detects an event (Before
Save) then it performs it's action. It has nothing to do with how often a
file is saved or such. The class is instanitated only once and the instance
persist for the duration of the Excel session.
--
HTH...

Jim Thomlinson


"tjh" wrote:

Thank you for your response,

This seems to work the first time that I click the save button, but if I
click the save button more than once while a workbook or workbook session is
open, the code does not run.
It appears that the problem is when we --- Set xlApp = New clsXLEvents
which is done when a workbook is opened or the addin is installed.

What would you suggest to be an appropriate event to allow for the setup,
which would allow for multiple saves.

Thank You,


"Jim Thomlinson" wrote:

The problem is that you are not saving the addin so the code does not fire.
To do waht you want is a bit more complicated. Here is some code...

In a new Class module name clsXLEvents
Option Explicit
Private WithEvents xlApp As Excel.Application

Private Sub Class_Initialize()
Set xlApp = Excel.Application
End Sub

Private Sub xlApp_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox "Tada"
End Sub

In a standard module named whatever
Option Explicit

Public xlApp As clsXLEvents

And in ThisWorkbook
Option Explicit

Private Sub Workbook_AddinInstall()
Set xlApp = New clsXLEvents
End Sub

Private Sub Workbook_AddinUninstall()
Set xlApp = Nothing
End Sub

Private Sub Workbook_Open()
Set xlApp = New clsXLEvents
End Sub

That should do what you want it to do...

--
HTH...

Jim Thomlinson


"tjh" wrote:

Hello,

I am trying to use an add-in, which will perform an action before saving to
the workbook. The before save event worked when I was using it as a normal
excel workbook, however when I changed it to an Add-in ---- the event does
not seem to work the same.

I am using an add-in because I would like this code to run anytime I save an
excel file.

Within the add-in I have the code to start the process in the VBAProject
"ThisWorkbook" using the BeforeSave event.

Any suggestions on getting this to run before any excel file is saved.

Thank You,

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
Totally Disabling (^ save ) (Save as) and Save Icon – Which code do I use: harpscardiff[_10_] Excel Programming 8 November 10th 05 12:24 PM
Save & Install AddIn with VBA Matt Excel Programming 1 September 23rd 04 03:40 PM
Excel Save pops up when unloading Addin file KimberlyC Excel Programming 0 June 9th 04 08:47 PM
save file as addin programatically Bura Tino Excel Programming 1 May 10th 04 06:07 PM
Remove Excel AddIn from AddIn List !! Help carl Excel Programming 2 December 8th 03 03:36 PM


All times are GMT +1. The time now is 09:44 AM.

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

About Us

"It's about Microsoft Excel"