Hi
Below is the full code which is contained within a UserForm – I have highlighted where I’ve tried to update the code to still work with XLS Padlock: -
Private Sub cmdExport_Click()
Dim i As Integer, sht As String
Application.ScreenUpdating = False
Application.EnableEvents = False
'save current view of visible worksheets
Dim CCnt As Byte
Dim Ckst As Worksheet
Dim CArr() As String
Dim Ckbk As Workbook
Dim Cnme As String
'Construct array containing
'names of current visible worksheets
'in this workbook
CCnt = 0
For Each Ckst In ThisWorkbook.Worksheets
If Ckst.Visible Then
CCnt = CCnt + 1
ReDim Preserve CArr(1 To CCnt)
CArr(CCnt) = Ckst.Name
End If
Next Ckst
'hide all the current visible sheets initially
Dim wsht As Object
For Each wsht In ThisWorkbook.Worksheets
If wsht.Name <> "Details" Then
wsht.Visible = False
End If
Next wsht
'Show list of all worksheets avaialble to export
For i = 0 To lstVisible.ListCount - 1
'select the required sheets
If lstVisible.Selected(i) = True Then
sht = lstVisible.List(i)
'hide the unselected sheets
Sheets(sht).Visible = True
End If
Next i
Unload Me
'Prepare only visible worksheets for export
Dim WCnt As Byte
Dim Wkst As Worksheet
Dim WArr() As String
Dim Wkbk As Workbook
Dim Fnme As String
Dim shp As Shape
'Hide Sheets That Are Not To Be Included
Sheets("Payment Breakdown").Visible = False
Sheets("Summary").Visible = False
'Construct array containing
'names of visible worksheets
'in this workbook
WCnt = 0
For Each Wkst In ThisWorkbook.Worksheets
If Wkst.Visible Then
WCnt = WCnt + 1
ReDim Preserve WArr(1 To WCnt)
WArr(WCnt) = Wkst.Name
End If
Next Wkst
'Copy visible worksheets
'to new workbook
ThisWorkbook.Worksheets(WArr).Copy
Set Wkbk = ActiveWorkbook
'Copy and paste values
'for each worksheet
'in new workbook
For Each Wkst In Wkbk.Worksheets
Wkst.Unprotect ("aaa")
With Wkst.Cells
.Copy
.PasteSpecial (xlPasteValues)
End With
'With Wkst
Application.CutCopyMode = False
Range("a1").Select
For Each shp In Wkst.Shapes
shp.Delete
Next shp
With Wkst.Cells.Validation
.Delete
End With
Application.CutCopyMode = False
Range("a1").Select
ActiveCell.Offset(1, 1).Select
ActiveCell.Offset(-1, -1).Select
Wkst.Protect ("aaa")
Next Wkst
'Construct file name
'for new workbook
With ThisWorkbook
Fnme = Left(.FullName, InStr(.FullName, ".") - 1) & _
"_" & Format(Now, "dd mmm yyyy_hh_mm_ss") & " SUBMISSION" & ".xlsx"
End With
'XLS FileName Function
'With ThisWorkbook
'Set xlspadlock = Application.COMAddIns("GXLSForm.GXLSFormula").Object
'Dim PathtoFile As String
'Filename = xlspadlock.PLEvalVAR("EXEPath") & Filename
' Fnme = Left(.PathtoFile, InStr(.PathtoFile, ".") - 1) & _
' "_" & Format(Now, "dd mmm yyyy_hh_mm_ss") & " SUBMISSION" & ".xlsx"
'End With
'Save and close
'new workbook
With Wkbk
.SaveAs _
Filename:=Fnme, _
FileFormat:=xlOpenXMLWorkbook
.Close
End With
'Activate this workbook
ThisWorkbook.Activate
'Notification that
'new workbook was created
MsgBox _
Prompt:="New workbook created:" & vbCrLf & Fnme, _
Buttons:=vbInformation
Application.EnableEvents = True
'Unhide Worksheets
For Each wsht In ThisWorkbook.Worksheets
If wsht.Name <> "Details" Then
wsht.Visible = False
End If
Next wsht
For Each Ckst In ThisWorkbook.Worksheets(CArr)
Ckst.Visible = True
Next Ckst
End Sub
I look forward to hearing from you.
Regards
Vince