I have learned a lot from this forum and nearing the end of my project. I want to be able to distribute updates to the distributed workbook. A few details:
1. The WB is protected.
2. All sheets are protected with UserInterfaceOnly= True. (All user interaction is via userforms and viewing of reports.)
3. The WB and sheets are protected via a PW that is set a a constant. The PW is the same on the old and new version of the WB.
What I need to do is copy a partial set of the sheets from the wbUserCopy to the wbNewVersion, at which point the user will start using the new version. I have that all working - but only if the wbUserCopy is unprotected and the affected sheets are visible. Here is some pared down version of the Update sub.
My questions are around how to unprotect the wbUserCopy.
1. Can I do it without it being opened?
2. Can I execute just the command in the Unpr_WB sub from the wbNewVersion, rather than call the sub?
3. Ho can I go about this? Any suggestions or help appreciated.
Thanks
1. The WB is protected.
2. All sheets are protected with UserInterfaceOnly= True. (All user interaction is via userforms and viewing of reports.)
3. The WB and sheets are protected via a PW that is set a a constant. The PW is the same on the old and new version of the WB.
What I need to do is copy a partial set of the sheets from the wbUserCopy to the wbNewVersion, at which point the user will start using the new version. I have that all working - but only if the wbUserCopy is unprotected and the affected sheets are visible. Here is some pared down version of the Update sub.
VBA Code:
Sub Start_Update()
sUserFileName = getFName(OpenFile)
'After FileOpen user selection
Set wbUserCopy = Workbooks(sUserFileName)
Set wbNewVersion = ThisWorkbook
'create backup
'displays modal userform to show processing
iRow = 1
Set rSheetList = wbNewVersion.Sheets("MySheet").Range("B61:B70")
'Need to unprotect the user copy here but this next command does not work
'Application.Run ("'" & wbUserCopy & "'!Unpr_WB")
For Each rCell In rSheetList
sSheet = rCell.Text
If sheetExist(sSheet, wbUserCopy) > 0 Then
sAfter = rCell.Offset(0, 1)
ThisWorkbook.Sheets("Sheet1").Visible = xlSheetVisible
If sheetExist(sSheet, wbNewVersion) > 0 Then
wbNewVersion.Sheets(sSheet).Visible = xlSheetVisible
wbNewVersion.Sheets(sSheet).Delete
VBA.DoEvents
'This IF statement does not work unless the WB is unprotected
If wbUserCopy.Sheets(sSheet).Visible = xlSheetVeryHidden Then
wbUserCopy.Sheets(sSheet).Visible = xlSheetVisible
End If
wbUserCopy.Sheets(sSheet).Copy Before:=wbNewVersion.Sheets("Sheet1")
wbUserCopy.Sheets(sSheet).Visible = xlSheetVeryHidden
'Check for successful copy of the sheet and logs success/failure
Else
'Same as the True without the sheet delete
End If
Else
'sets some variables
End If
iRow = iRow + 1
Next
'then runs some closing commands
End Sub
My questions are around how to unprotect the wbUserCopy.
1. Can I do it without it being opened?
2. Can I execute just the command in the Unpr_WB sub from the wbNewVersion, rather than call the sub?
VBA Code:
ThisWorkbook.Protect Password:=PW, Structure:=True"
Thanks