Keijir Blog

やっぱハワイ行きたいよね

Microsoft Office 64bitのマクロで7Zipを使う方法

7Zip64.DLLを入手

http://ayakawa.o.oo7.jp/
7-zip64.dll ver 9.22.00.02 私家版 を入手

DLLを保存

解凍してDLLを
C:\Windows\System32\7-zip64.dll へ保存

マクロ

https://hatenachips.blog.fc2.com/blog-entry-376.html を参考に
64bitヘ変更 (Declare と Longの記述を修正)

Private Declare PtrSafe Function SevenZip Lib "7-zip64.DLL" ( _
    ByVal hWnd As LongPtr, _
    ByVal szCmdLine As String, _
    ByVal szOutput As String, _
    ByVal dwSize As LongPtr) As LongPtr

'ZIPファイルを解凍
'引数 sDstPath:解凍先のフォルダーのパス
'     sZIPFile:ZIPファイルのパス
'     sPassWord:パスワード 省略可
'返り値 成功したら True、失敗したらFalse
Public Function ExtractZIP( _
    sDstPath As String, sZIPFile As String, Optional sPassWord As String = "") As Boolean
    Dim sCmd As String
    sCmd = "X -hide -aoa "
    If sPassWord <> "" Then sCmd = sCmd & "-P" & sPassWord & " "
    sCmd = sCmd & Q2(sZIPFile) & " -o" & Q2(sDstPath)
    ExtractZIP = DoSevenZip(sCmd) = 0
End Function

Private Function DoSevenZip(sCmd As String) As LongPtr
    Dim sRet As String * 1024
    DoSevenZip = SevenZip(0, sCmd, sRet, 1024)
    If DoSevenZip <> 0 Then MsgBox (Left(sRet, InStr(sRet, vbNullChar) - 1))
End Function

Public Function Q2(ByVal Text As String) As String
    Q2 = """" & Replace(Text, """", """""") & """"
End Function


これでまたメールの添付ファイルを自動保存できる!