Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Totally Disabling (^ save ) (Save as) and Save Icon – Which code do I use: | Excel Programming | |||
Save & Install AddIn with VBA | Excel Programming | |||
Excel Save pops up when unloading Addin file | Excel Programming | |||
save file as addin programatically | Excel Programming | |||
Remove Excel AddIn from AddIn List !! Help | Excel Programming |