PDA

View Full Version : [SOLVED:] Can a Add-in detect when you save a different workbook?



Ago
05-15-2014, 03:56 AM
I have a add-in that detects when I open a CSV-file, and does some calculation.
After the calculations are done the user ends up with a "draft" excel file.
The filename is still *.CSV but because there are several sheets now if you save it you have to save it as a excel file.
Can I with the add-in detect if/when the user saves the file?
As a before_save()?

What I want to do is if the user chooses to save the file add a extra line before it's saved.

Bob Phillips
05-15-2014, 06:19 AM
Use application events


Public WithEvents App As Application

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Wb.FileFormat = xlCSV Then

'your code here
End If
End Sub

Private Sub Workbook_Open()
Set App = Application
End Sub

snb
05-15-2014, 08:45 AM
What's the benefit of an extra line ?

Ago
05-16-2014, 02:53 AM
Use application events


Public WithEvents App As Application

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Wb.FileFormat = xlCSV Then

'your code here
End If
End Sub

Private Sub Workbook_Open()
Set App = Application
End Sub


Thanks!
Have not yet tested it but it seems to do the job.