+ Reply to Thread
Results 1 to 8 of 8

Thread: Modify Macro to Run on Protected Shet

  1. #1
    Registered User
    Join Date
    01-31-2011
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003
    Posts
    24

    Modify Macro to Run on Protected Shet

    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

  2. #2
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,231

    Re: Modify Macro to Run on Protected Shet

    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

  3. #3
    Registered User
    Join Date
    01-31-2011
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Modify Macro to Run on Protected Shet

    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

  4. #4
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,231

    Re: Modify Macro to Run on Protected Shet

    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

  5. #5
    Registered User
    Join Date
    01-31-2011
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Modify Macro to Run on Protected Shet

    Same errror Same error message as well - macro cannot be run on protected...etc

  6. #6
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,231

    Re: Modify Macro to Run on Protected Shet

    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.

  7. #7
    Registered User
    Join Date
    01-31-2011
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Modify Macro to Run on Protected Shet

    Pls find attached the actual workbook. many thanks for all your help!
    Attached Files Attached Files

  8. #8
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,231

    Re: Modify Macro to Run on Protected Shet

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0