使用VBS脚本无障碍打开加密Excel文件

因经常接触加密Excel数据文件,密码又难记,所以有此办法

复制下面代码到记事本,另存为 【快捷打开.vbs】 文件

Set args = Wscript.Arguments
FilePath = args(0)
Const Pwd = "xxxxx" '事先知道的Excel文件密码,是打开密码,不是工作簿密码
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.WorkBooks.Open FilePath,0,True,,Pwd
tittle = "JBH Only"
objExcel.Caption = tittle
set ws=createobject("wscript.shell")
ws.appactivate tittle
ws.sendkeys "{enter}"
ws.quit
set ws = nothing
set args = nothing

【vbRichclient】神模块

参见

【XML、HTML的XPath定位模块】

参考下面范例

Sub Xpath定位() 'MSXML2.DOMDocument.6.0
    Const str_Html As String = _
        "<div id = ""outside"">" & _
            "<div id =""box"">" & _
                "<div id = ""head"" class = ""color0"">AAA</div>" & _
                "<div id = ""body"" class = ""color1"">BBB</div>" & _
                "<div id = ""footer1"" class = ""color1"">" & _
                    "<div id = ""footer2"" class = ""color2"">CCC</div>" & _
                "</div>" & _
            "</div>" & _
        "</div>"
    Dim xmlDom As New MSXML2.DOMDocument60  '引用Microsoft xml,v6.0
'    Dim xmlDom As Object
'    Set xmlDom = CreateObject("Msxml2.DOMDocument.6.0")

    If Not xmlDom.LoadXML(str_Html) Then
        MsgBox xmlDom.parseError.reason
        Set xmlDom = Nothing
        Exit Sub
    End If
    Debug.Print xmlDom.SelectSingleNode("//div/ @ id").Text '根路径下div id
    Debug.Print xmlDom.SelectSingleNode("//div/div/ @ id").Text
    Debug.Print xmlDom.SelectSingleNode("//div/div[ @ class = ""color1""]").Text
    Debug.Print xmlDom.SelectSingleNode("//div/div[ @ id=""body""]").Text
    Debug.Print xmlDom.SelectNodes("//div/div/@id")(0).Text
    Debug.Print xmlDom.SelectNodes("//div/div/@id")(2).Text
    Debug.Print xmlDom.SelectNodes("//div/div[@id=""footer2""]")(0).Text '只有一个结果
    Debug.Print xmlDom.SelectNodes("//div [@id=""box""] /div [@class=""color1"" ] ")(0).Text
    Debug.Print xmlDom.SelectNodes("//div/div/@id")(0).XML

    Set xmlDom = Nothing
End Sub

【Mail模块】【VBA常用模块】仅适用VB7 64位,2种方式

两种方式,一种需要本机Outlook配置好的,一种不需要,使用CDO

一、Outlook模式

该模式需要你电脑中有正常使用的Outlook,不是装了软件就可以了,要配置好正常能用

用例

Sub test()
    Set mm = New MailForOutlook
    s = mm.GenerateEmail("gnefnuy@qq.com", "主题:测试", "<b>加粗</b><br>测试", True)
End Sub

【MD5模块和UTF8转换模块】【VBA常用模块】仅适用VB7 64位,已验证

用例,VBA的环境是GB2312的,直接MD5中文字符出来的会与实际通用的UTF8字符数据不一致,所以要先转UTF8再MD5


Sub test()
    Dim f As New MD5
    Dim s As String
    s = "中文字"
    Debug.Print "ANSI:" & f.DigestStrToHexStr(s)
    Dim a() As Byte, b() As Byte
    a = s
    Debug.Print "GB2312:" & f.DigestByteToHexStr(a)
    Debug.Print "GB2312-UTF8:" & f.DigestByteToHexStr(Unicode_To_UTF8(a)) '这里的数据和网上在线MD5验证网站一致。
    b = StrConv(s, vbFromUnicode)
    Debug.Print "ANSI-UTF8:" & f.DigestByteToHexStr(Unicode_To_UTF8(b))
End Sub
<< 1 >>

Powered By Z-BlogPHP 1.7.0

@2021 yunfeng.net.cn 版权所有
浙ICP备16007973号-1