I have an invoice I am working on for a local business it needs to be protected so the employees do not alter the formulas but I also have a clear contents function. When I protect the sheet the clear contents gives errors I assume the protection is preventing the clear contents from running. I have some code I have been piecing together from different forums and I think I am close to getting it right I just need a little help. I have a VB button on the worksheet that the user presses to clear contents and save a copy of the invoice while generating another invoice number as well. I keep getting "compile error: Invalid or unqualified reference" Any help would be greatly appreciated.
The name of the work sheet is: TMR MASTER INVOICE
The code I am using:
Sub NextInvoice()
Range("D6").Value = Range("D6").Value + 1
.Unprotect Password:="reco1966"
Range("A9:A12,A14:C21,A27:C34,D7,D9,D11,D39").ClearContents
.Protect Password:="reco1966"
End Sub
___________________________________________________________________
Sub SaveInvWithNewName()
Dim NewFN As Variant
' Copy Invoice to a new workbook
ActiveSheet.Copy
NewFN = "C:\TMR\Inv" & Range("D6").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
NextInvoice
End Sub
The name of the work sheet is: TMR MASTER INVOICE
The code I am using:
Sub NextInvoice()
Range("D6").Value = Range("D6").Value + 1
.Unprotect Password:="reco1966"
Range("A9:A12,A14:C21,A27:C34,D7,D9,D11,D39").ClearContents
.Protect Password:="reco1966"
End Sub
___________________________________________________________________
Sub SaveInvWithNewName()
Dim NewFN As Variant
' Copy Invoice to a new workbook
ActiveSheet.Copy
NewFN = "C:\TMR\Inv" & Range("D6").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
NextInvoice
End Sub
Last edited: