+ Reply to Thread
Results 1 to 4 of 4

Copying existing password protected sheet to new workbook as unprotected sheet error

Hybrid View

bhsingh Copying existing password... 01-27-2016, 04:25 PM
FDibbins Re: Copying existing password... 01-28-2016, 12:52 AM
bhsingh Re: Copying existing password... 01-28-2016, 09:17 AM
bhsingh Re: Copying existing password... 01-29-2016, 03:57 PM
  1. #1
    Registered User
    Join Date
    01-27-2016
    Location
    Ottawa, Canada
    MS-Off Ver
    2013
    Posts
    3

    Copying existing password protected sheet to new workbook as unprotected sheet error

    Copying an existing password protected sheet to a new workbook as an unprotected sheet gives the following error when user tries to type in data in the new worksheet.

    Error: "the cell or chart you're trying to change is on a protected sheet"

    This error happens only once. Click OK on the pop up error message and type again in a cell, then excel allows you to type data in the cells and save the sheet.

    We have an excel (format .xls) file currently being used to create another excel spreadsheet when a button on a form in the same spreadsheet is clicked. It basically copies one password protected blank sheet (a template) to a new workbook as an unprotected sheet. The code below used to work with excel 2007(using .xls format). We recently upgraded from excel 2007 to excel 2013.

    Private Sub cmdCancellation_Click()
    Dim jBook As Workbook
    Dim jsheet As Worksheet
    
    CurrentWorkBook = ActiveWorkbook.Name
    Workbooks(CurrentWorkBook).Unprotect jWorksheetPassword
    'catch all for errors
    On Error GoTo ErrEnd
    Dim orginalScreenUpdating As Boolean
    orginalScreenUpdating = Application.ScreenUpdating
    Application.ScreenUpdating = False
    
    If Range("Language").Value = "2" Then
        'French
        Set jsheet = EPIPTemplateCancelFR
    Else
        'english
        Set jsheet = EPIPTemplateCancelEN
    End If
    
    jsheet.Visible = xlSheetHidden
    'jSheet.Visible = xlSheetVisible
    
    'Delete this line
    jsheet.Unprotect jWorksheetPassword
    
    Set jBook = Workbooks.Add(xlWBATWorksheet)
    jsheet.Copy After:=jBook.Sheets(1)
    jBook.Sheets(2).Visible = xlSheetVisible
    
    Application.DisplayAlerts = False
    jBook.Sheets(1).Delete
    Application.DisplayAlerts = True
    
    jsheet.Visible = xlSheetVeryHidden
    
    'Delete this line
    jBook.Sheets(1).Unprotect jWorksheetPassword
    'Delete this line
    'jsheet.Protect Password:=jWorksheetPassword
    
    NoErrEnd:
    Workbooks(CurrentWorkBook).Protect Password:=jWorksheetPassword, Structure:=True, Windows:=False
    Application.ScreenUpdating = orginalScreenUpdating
    Unload Me
    Exit Sub
    
    ErrEnd:
    Workbooks(CurrentWorkBook).Protect Password:=jWorksheetPassword, Structure:=True, Windows:=False
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    MsgBox DataTable.Range("MSG4").Value, vbCritical, DataTable.Range("MSG4TITLE").Value
    Unload Me
    
    
    End Sub
    However the newly created sheet always shows the error message pop up shown in bold above whenever the user tries to enter in data in the new workbook. Any help or suggestions would be appreciated.
    PS: please ignore the code where it says 'Delete this line
    Last edited by bhsingh; 01-28-2016 at 02:46 PM. Reason: additional info provided

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Copying existing password protected sheet to new workbook as unprotected sheet error

    Do you actually have the password for this? If not, then we cannot help you
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    01-27-2016
    Location
    Ottawa, Canada
    MS-Off Ver
    2013
    Posts
    3

    Re: Copying existing password protected sheet to new workbook as unprotected sheet error

    Yes I have the password for this sheet
    Workbooks(CurrentWorkBook).Unprotect jWorksheetPassword
    jWorksheetPassword is a global variable that is defined elsewhere. Password is hard coded in the vba as plain text.

  4. #4
    Registered User
    Join Date
    01-27-2016
    Location
    Ottawa, Canada
    MS-Off Ver
    2013
    Posts
    3

    Re: Copying existing password protected sheet to new workbook as unprotected sheet error

    I found a hack that works. I activate the original workbook and this somehow clears the protection of the copied sheet with excel 2013 only. On Excel 2007 this causes the original workbook to be activated and confuses users, hence the check for 2013.

    If Application.Version = "15.0" Then
    Workbooks(CurrentWorkBook).Activate
    'jBook.Activate
    End If


    The full code is as follows:
    Private Sub cmd_Click()
    Dim jBook As Workbook
    Dim jsheet As Worksheet
    
    CurrentWorkBook = ActiveWorkbook.Name
    Workbooks(CurrentWorkBook).Unprotect jWorksheetPassword
    'catch all for errors
    On Error GoTo ErrEnd
    Dim orginalScreenUpdating As Boolean
    orginalScreenUpdating = Application.ScreenUpdating
    Application.ScreenUpdating = False
    
    If Range("Language").Value = "2" Then
        'French
        Set jsheet = TemplateFR
    Else
        'english
        Set jsheet = TemplateEN
    End If
    
    jsheet.Visible = xlSheetHidden
    
    Set jBook = Workbooks.Add(xlWBATWorksheet)
    jsheet.Copy After:=jBook.Sheets(1)
    jBook.Sheets(2).Visible = xlSheetVisible
    
    Application.DisplayAlerts = False
    jBook.Sheets(1).Delete
    Application.DisplayAlerts = True
    
    If Application.Version = "15.0" Then
        Workbooks(CurrentWorkBook).Activate
        'jBook.Activate
    End If
    
    jsheet.Visible = xlSheetVeryHidden
    
    NoErrEnd:
    Workbooks(CurrentWorkBook).Protect Password:=jWorksheetPassword, Structure:=True, Windows:=False
    Application.ScreenUpdating = orginalScreenUpdating
    Unload Me
    Exit Sub
    
    ErrEnd:
    Workbooks(CurrentWorkBook).Protect Password:=jWorksheetPassword,     Structure:=True, Windows:=False
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    MsgBox DataTable.Range("MSG4").Value, vbCritical,     DataTable.Range("MSG4TITLE").Value
    Unload Me
    
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copying unprotected data from one sheet of workbook to another workbook
    By rushabh bhansali in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2013, 06:18 AM
  2. Sheet Protected - Message on unprotected cells?
    By VWAviator in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2013, 04:21 AM
  3. Protected sheet gets unprotected when copy paste.
    By Jeyakumar in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 03-08-2013, 02:03 AM
  4. Replies: 2
    Last Post: 06-09-2012, 09:08 AM
  5. Copy protected sheet as unprotected
    By davegugg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-09-2009, 03:06 PM
  6. Error Handler for Incorrect Password (Protected Sheet)
    By jasoncw in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-01-2007, 06:44 PM
  7. PLEASE HELP! Copy sheet with password protected cells debug error
    By bsnapool in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2006, 07:04 AM
  8. Protected sheet to unprotected sheet
    By CaptainIrony@gmail.com in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-26-2005, 01:05 PM

Tags for this Thread

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.6.0 RC 1