The below code works perfectly on my existing sheet however its causing an error ever since i inserted 2 columns and protected the sheet. Can you please help in the added code for it to work on a protected sheet as well?
Sorry, if i have pasted the code in a wrong methodology.
Sub Printsave() Dim thatwb As Workbook 'Sheets("Table").PrintOut fname = Range("M5").Value Set thatwb = Workbooks.Add With thatwb .SaveAs Filename:="\\changeme1\d\Windows\Window\GAG Monthly\GAG_" & Format(fname, "DDMMYYYY") & ".xlsx" .Sheets(1).Name = "GAGDaily" ThisWorkbook.Sheets("Data").Cells(1, 2).CurrentRegion.Copy _ Destination:=.Sheets("GAGDaily").Range("A1") .Close True End With Sheets("Data").Range("B2:E101").ClearContents Sheets("Data").Range("H2:H101").ClearContents ActiveSheet.Protect End Sub
Last edited by TMShucks; 02-09-2012 at 12:42 PM. Reason: Remove extra tags
Put:
Sheets("GAGDaily").Unprotect Password:="xxx" ThisWorkbook.Sheets("Data").Cells(1, 2).CurrentRegion.Copy _ Destination:=.Sheets("GAGDaily").Range("A1") Sheets("GAGDaily").Protect Password:="xxx"
Regards, TMS
Hi, i inserted your code, but am still facing an error. Many thanks for your help!
Sub Printsave() Dim thatwb As Workbook 'Sheets("Table").PrintOut fname = Range("M5").Value Set thatwb = Workbooks.Add With thatwb .SaveAs Filename:="\\changeme1\d\Windows\Window\GAG Monthly\GAG_" & Format(fname, "DDMMYYYY") & ".xlsx" .Sheets(1).Name = "GAGDaily" Sheets("GAGDaily").Unprotect Password:="r888" ThisWorkbook.Sheets("Data").Cells(1, 2).CurrentRegion.Copy _ Destination:=.Sheets("GAGDaily").Range("A1") Sheets("GAGDaily").Protect Password:="r888" .Close True End With Sheets("Data").Range("B2:E101").ClearContents Sheets("Data").Range("H2:H101").ClearContents End Sub
Maybe:
Sub Printsave() Dim thatwb As Workbook 'Sheets("Table").PrintOut fname = Range("M5").Value Set thatwb = Workbooks.Add With thatwb .SaveAs Filename:="\\changeme1\d\Windows\Window\GAG Monthly\GAG_" & Format(fname, "DDMMYYYY") & ".xlsx" .Sheets(1).Name = "GAGDaily" .Sheets("GAGDaily").Unprotect Password:="r888" ThisWorkbook.Sheets("Data").Cells(1, 2).CurrentRegion.Copy _ Destination:=.Sheets("GAGDaily").Range("A1") .Sheets("GAGDaily").Protect Password:="r888" .Close True End With Sheets("Data").Range("B2:E101").ClearContents Sheets("Data").Range("H2:H101").ClearContents End Sub
Regards, TMS
Same errrorSame error message as well - macro cannot be run on protected...etc
Please post a sample workbook.
Regards, TMS
To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook. Don't upload a picture when you have a workbook question. None of us is inclined to recreate your data. Upload the workbook and manually add an 'after' situation so that we can see what you expect. In addition clearly explain how you get the results..
To attach a file to your post, you need to be using the main 'New Post' or 'New Thread' page and not 'Quick Reply'.
To use the main 'New Post' page, click the 'Post Reply' button in the relevant thread.
On this page, below the message box, you will find a button labelled 'Manage Attachments'.
Clicking this button will open a new window for uploading attachments.
You can upload an attachment either from your computer or from another URL by using the appropriate box on this page.
Alternatively you can click the Attachment Icon to open this page.
To upload a file from your computer, click the 'Browse' button and locate the file.
To upload a file from another URL, enter the full URL for the file in the second box on this page.
Once you have completed one of the boxes, click 'Upload'.
Once the upload is completed the file name will appear below the input boxes in this window.
You can then close the window to return to the new post screen.
Pls find attached the actual workbook. many thanks for all your help!
I was confused about which worksheet was protected. Try:
Sub Printsave() Dim thatwb As Workbook 'Sheets("Table").PrintOut fname = Range("M5").Value Set thatwb = Workbooks.Add With thatwb .SaveAs Filename:="GAG_" & Format(fname, "DDMMYYYY") & "y.xlsx" .Sheets(1).Name = "GAGDaily" ThisWorkbook.Sheets("Data").Unprotect Password:="r888" ThisWorkbook.Sheets("Data").Cells(1, 2).CurrentRegion.Copy _ Destination:=.Sheets("GAGDaily").Range("A1") ThisWorkbook.Sheets("Data").Protect Password:="r888" .Close True End With With ThisWorkbook.Sheets("Data") .Unprotect Password:="r888" .Range("B2:E101").ClearContents .Range("H2:H101").ClearContents .Protect Password:="r888" End With End Sub
Regards, TMS
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks