Board logo

標題: [發問] 工作表另存檔案及被保護工作表 [打印本頁]

作者: missbb    時間: 2017-12-3 21:37     標題: 工作表另存檔案及被保護工作表

各位大大, 我有下列將工作部內的工作表另存獨立WORKBOOK, 但想另存後的工作表是已受保護的工作表, 解除PASSWORD是1, 請賜教?
  1. Sub Splitbook()
  2. 'Updateby20140612
  3. Dim xPath As String
  4. xPath = Application.ActiveWorkbook.Path
  5. Application.ScreenUpdating = False
  6. Application.DisplayAlerts = False
  7. For Each xWs In ThisWorkbook.Sheets
  8.     xWs.Copy
  9.     Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name & ".xls" [color=Red](問題, 如何另存新檔後, 每個檔案都已保護了工作表, PASSWORD 是"1")[/color]
  10.     Application.ActiveWorkbook.Close False
  11. Next
  12. Application.DisplayAlerts = True
  13. Application.ScreenUpdating = True
  14. End Sub
複製代碼

作者: Hsieh    時間: 2017-12-4 09:43

回復 1# missbb
  1. Sub Splitbook()
  2. XPath = Application.ActiveWorkbook.Path
  3. For Each xws In Sheets
  4. xws.Copy '複製
  5. ActiveSheet.Protect 1 '保護工作表密碼1
  6. With ActiveWorkbook
  7. .SaveAs XPath & "\" & xws.Name & ".xls", , 1  '另存新檔並保護活頁簿密碼1
  8. .Close '關閉檔案
  9. End With
  10. Next
  11. End Sub
複製代碼





歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)