"Workbook_AfterSave" not letting me saveas

B

bony_tony

Hi,
I have the code below which removes some references so that users with
different different Office versions can open the file without
problems, it then cheats by saving the file and adds the references
again so the current user still has them.

The problem is that when SaveAs is used the event is still called and
the file is saved in the normal way.

Is there any way around this? ie If SaveType = "SaveAs" Then Exit
Sub??

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

On Error Resume Next
Dim xObject As Object

Set xObject = ThisWorkbook.VBProject.References.Item("Outlook")
ThisWorkbook.VBProject.References.Remove xObject

Set xObject = ThisWorkbook.VBProject.References.Item("Word")
ThisWorkbook.VBProject.References.Remove xObject

Application.EnableEvents = False
Me.Save
Application.EnableEvents = True

On Error Resume Next
AddReferenceFromGUID "{00020905-0000-0000-C000-000000000046}", 5,
0
AddReferenceFromGUID "{00062FFF-0000-0000-C000-000000000046}", 5,
0
ThisWorkbook.Saved = True
Cancel = True

End Sub
 
G

Guest

One of the arguments of the procedure is
ByVal SaveAsUI As Boolean

so you can tell if the save is the result of a save as...

If SaveAsUI then exit sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top