I have put the following code in a module in a workbook of 6 worksheets but with only 2 worksheets showing. Worksheets need to be protected. As soon as user clicks opens the file, it opens immediately, adds one to the qtn number and closes immediately saving a new file with the new qtn number. What i wish the code to do is that when user opens the file it opens up, but then stays open until user input new data, and then when user clicks a button the new qtn file with the incremented qtn number is created and saved.
Sub Call_mycode()
Dim CSName As String
Dim CSNumber As String
'This is the cell containing the name for the new book.
With Worksheets("PRICELIST")
CSNumber = .Range("c20").Text & .Range("c21").Text
End With
CSName = Worksheets("PRICELIST").Range("b22").Text
'ActiveWorkbook.Sheets.Select
'ActiveWorkbook.Unprotect
'Make a copy of the original workbook.
Sheets.Copy
Sheets("qtn").Select
ActiveSheet.Activate
'Save the new workbook.
Sheets("qtn").Select
ActiveSheet.Unprotect
ActiveSheet.DrawingObjects.Delete
ActiveSheet.Protect
ChDir ("C:\Autonumbering1")
ActiveWorkbook.SaveAs ("QCLK " & CSNumber & "08" & " " & CSName & CSNumber)
'ActiveWorkbook.SaveAs (CSNumber & " " & CSName)
'Close the new saved workbook.
Sheets("qtn").Select
ActiveWorkbook.Close
'Close the original workbook
Sheet2.Unprotect
'ActiveSheet.Unprotect
Sheet2.Activate
Sheets("qtn").Unprotect
Range("c21").Select
ActiveCell.FormulaR1C1 = "=R[-1]C+1"
Range("c21").Select
Selection.Copy
Range("c20").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("c21").Select
Selection.ClearContents
'Sheets("qtn").Protect
'Protect PRICELIST
Sheet2.Select
Range("e1:g2").ClearContents
'Range("b20:c20").ClearContents
Range("b22:c25").ClearContents
Range("g21:h25").ClearContents
Range("e33:e37").ClearContents
Range("e40:e51").ClearContents
Range("e54:e59").ClearContents
Range("e62:e64").ClearContents
Range("e68:e70").ClearContents
Range("e73:e81").ClearContents
Range("e84:e89").ClearContents
Range("e92:e96").ClearContents
Range("e99:e101").ClearContents
Range("e106:e131").ClearContents
Range("e146").ClearContents
Range("a157:e166").ClearContents
Range("g157:h166").ClearContents
'Range("A4").Select
Sheets("PRICELIST").Protect
Sheet7.Select
ActiveWorkbook.Close (False)
ActiveWorkbook.Save
End Sub
Can someone indicate what I am doing wrong and how should the code be to have it doing what I need it to do.
Thks
Paraxis
Bookmarks