我用谷歌搜索过,但运气不佳。基本上,每次创建 Excel 电子表格(基于模板)都需要密码保护。这可以吗?
'______________________CreateExcel()____________________________________
Function CreateExcel()
SELECT DATA FROM SQL TABLE
If objStructure.BOF = False And objStructure.EOF = False Then
Do While objStructure.EOF = False
Call CreateActualExcel()
objRsExcel.Fields("Field") = objStructure.Fields("Field")
objStructure.MoveNext
Loop
End If
End Function
'......................End CreateExcel()..................................
'______________________CreateActualExcel()________________________________
Sub CreateActualExcel()
Dim objSFSO
Dim strCon, strSQL
strFile = " Staffing_List_" & Clng(Timer()) & ".xls"
Set objSFSO = CreateObject("Scripting.FileSystemObject")
objSFSO.CopyFile conFolder & conTemplate, conFolder & strFile
Set objSFSO = Nothing
Set objRsExcel = CreateObject("ADODB.RecordSet")
strCon = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
conFolder & strFile & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;maxscanrows=1;"";"
strSQL = "Select * From [Sheet1$]"
objRsExcel.Open strSql, strCon, 3, 2
End Sub
'......................End CreateActualExcel()............................
预先感谢您的帮助。
克莱尔:-)
最佳答案
我认为您可以在保存文件时将密码作为附加参数传递。
excelObj.SaveAs "C:\Example.xls",,"您的密码"
我还没有测试过这个,但我找到了这篇关于它的博客文章:
http://qtp.blogspot.co.uk/2010/04/vbscript-excel-password-protect.html
关于excel - vbscript,Excel 8.0 工作表上的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10108638/