delete a macro

haithamjo91

New Member
Joined
Jun 18, 2021
Messages
2
Platform
  1. Windows
hello everybody,

i have a problem when i run this code, it gives me (object required). can anybody help plz.

VBA Code:
Private Sub Workbook_Open()
    ActiveSheet.Unprotect
    Range("A17:F34").Clearcontents
    Range("B11:D15").Clearcontents
    Range("F11:G15").Clearcontents
    Range("G9").Clearcontents
    Range("G8").Clearcontents
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Sub Clearcontents()
    ActiveSheet.Unprotect
    Range("A17:F34").Clearcontents
    Range("B11:D15").Clearcontents
    Range("F11:G15").Clearcontents
    Range("G9").Clearcontents
    Range("G8").Clearcontents
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Sub SaveInvoiceAsPDFAndClear()
    ActiveSheet.Unprotect
    Dim NewFN As Variant
    ' Create the PDF First
    NewFN = "Z:\Soumission\" & Range("G2").Value & " - " & Range("G9").Value & ".pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
    ' Next, Save the Excel File
    Dim NewFN2 As Variant
    ActiveWorkbook.Copy
    NewFN2 = "Z:\Soumission\" & Range("G2").Value & " - " & Range("G9").Value & ".xlsx"
    ActiveWorkbook.Sheets("Facture").SaveAs NewFN2, FileFormat:=xlOpenXMLWorkbook
    ActiveWorkbook.Close
    NewFN2.Activate
    NewFN2.Sheets("Facture").Shapes("Save").Delete
    ' Increment the invoice number
    Range("G2").Value = Left(Range("G2").Value, 11) & Year(Now) & Mid(Range("G2").Value, 16, 3) + 1
    ' Clear out the invoice fields
    Range("A17:F34").Clearcontents
    Range("B11:D15").Clearcontents
    Range("F11:G15").Clearcontents
    Range("G9").Clearcontents
    Range("G8").Clearcontents
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Private Sub sb_Copy_Save_ActiveSheet_As_Workbook()
    NewFN2.Activate
    NewFN2.Sheets("Facture").Shapes("Save").Delete
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.DisplayAlerts = False
        ActiveWorkbook.Save
    Application.DisplayAlerts = True
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
hello everybody,

i have a problem when i run this code, it gives me (object required). can anybody help plz.

VBA Code:
Private Sub Workbook_Open()
    ActiveSheet.Unprotect
    Range("A17:F34").Clearcontents
    Range("B11:D15").Clearcontents
    Range("F11:G15").Clearcontents
    Range("G9").Clearcontents
    Range("G8").Clearcontents
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Sub Clearcontents()
    ActiveSheet.Unprotect
    Range("A17:F34").Clearcontents
    Range("B11:D15").Clearcontents
    Range("F11:G15").Clearcontents
    Range("G9").Clearcontents
    Range("G8").Clearcontents
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Sub SaveInvoiceAsPDFAndClear()
    ActiveSheet.Unprotect
    Dim NewFN As Variant
    ' Create the PDF First
    NewFN = "Z:\Soumission\" & Range("G2").Value & " - " & Range("G9").Value & ".pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
    ' Next, Save the Excel File
    Dim NewFN2 As Variant
    ActiveWorkbook.Copy
    NewFN2 = "Z:\Soumission\" & Range("G2").Value & " - " & Range("G9").Value & ".xlsx"
    ActiveWorkbook.Sheets("Facture").SaveAs NewFN2, FileFormat:=xlOpenXMLWorkbook
    ActiveWorkbook.Close
    NewFN2.Activate
    NewFN2.Sheets("Facture").Shapes("Save").Delete
    ' Increment the invoice number
    Range("G2").Value = Left(Range("G2").Value, 11) & Year(Now) & Mid(Range("G2").Value, 16, 3) + 1
    ' Clear out the invoice fields
    Range("A17:F34").Clearcontents
    Range("B11:D15").Clearcontents
    Range("F11:G15").Clearcontents
    Range("G9").Clearcontents
    Range("G8").Clearcontents
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Private Sub sb_Copy_Save_ActiveSheet_As_Workbook()
    NewFN2.Activate
    NewFN2.Sheets("Facture").Shapes("Save").Delete
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.DisplayAlerts = False
        ActiveWorkbook.Save
    Application.DisplayAlerts = True
End Sub
what i want is to delete the macro button in the new excel file (copied)
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,168
Members
448,870
Latest member
max_pedreira

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top