如何在HTA上的vbscript中使用以下内容。
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True
如果我尝试使用":=" ,它会引发页面错误。
谢谢, 阿南德
答案 0 :(得分:0)
“移植”VBA代码,如
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True
要在.HTA(主机:mshta.exe)或.VBS(主机c / wscript.exe)中使用的VBScript,你必须
开始研究here。
答案 1 :(得分:0)
我找到了另一种方法。我将所需的代码插入到对象Excel的VB代码模块中。 像下面的东西。
With myReport.VBProject.VBComponents("ThisWorkbook").CodeModule
.InsertLines .CountOfLines + 1, _
"Private Sub Workbook_Open()" & Chr(13) & _
" ProtectMe(1)" & vbNewLine & _
"End Sub" & vbNewLine & _
"Sub ProtectMe(Status)" & vbNewLine & _
" Dim mySheet As Worksheet" & vbNewLine & _
" Dim myPassword " & vbNewLine & _
" myPassword = ""IamGenius""" & vbNewLine & _
" For Each mySheet In ThisWorkbook.Worksheets" & vbNewLine & _
" mySheet.Protect Password:=myPassword, DrawingObjects:=True, _" & vbNewLine & _
" Contents:=True, Scenarios:=True, AllowFormattingCells:=True, _" & vbNewLine & _
" AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFiltering:=True" & vbNewLine & _
" mySheet.EnableSelection = xlUnlockedCells" & vbNewLine & _
" Next mySheet" & vbNewLine & _
"End Sub"
End With
谢谢, 阿南德:)