工作表上的vbscript,excel 8.0密码

时间:2012-04-11 15:01:39

标签: excel vbscript scheduled-tasks

我用Google搜索没有太多运气。基本上每个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()............................

提前感谢您的帮助。

克莱尔: - )

1 个答案:

答案 0 :(得分:2)

我认为您可以在保存文件时将密码作为附加参数传递。

excelObj.SaveAs“C:\ Example.xls”,,“your-password”

我没有对此进行过测试,但我发现了这篇关于它的博文:

http://qtp.blogspot.co.uk/2010/04/vbscript-excel-password-protect.html