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
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