EXCEL如何用VBA实现根据a.xls中的内容生成b.xls,生成的同时将b.xls加密(即有打开密码)
展开全部
Sub t()
Application.DisplayAlerts = False
Dim wb As Workbook
Dim p As String
p = ThisWorkbook.Path
ThisWorkbook.Worksheets("Sheet1").Copy
Set wb = ActiveWorkbook
With wb
wb.SaveAs p & "\b.xls"
ActiveWorkbook.Worksheets("Sheet1").Protect Password:="123"
wb.Close True
End With
End Sub
追问
出来的b.xls能打开,只是不能修改,我需要的效果是打开b.xls时,需要输入密码
追答
Sub t()
Application.DisplayAlerts = False
Dim wb As Workbook
Dim p As String
p = ThisWorkbook.Path
ThisWorkbook.Worksheets("Sheet1").Copy
Set wb = ActiveWorkbook
With wb
wb.SaveAs p & "\b.xls", Password:="123", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
ActiveWorkbook.Worksheets("Sheet1").Protect Password:="123"
wb.Close True
End With
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询