0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VBAテスト

Last updated at Posted at 2025-03-09

Sub SaveSelectedEmailAttachments()
Dim sourceExtension As String
Dim destinationFolder As String
Dim email As MailItem
Dim attachments As Attachments
Dim attachment As attachment
Dim senderEmail As String
Dim receivedDate As String
Dim newName As String
Dim destinationPath As String
Dim tempPath As String

' 拡張子と保存先フォルダを設定
sourceExtension = ".zi"
destinationFolder = "C:\Temp"

' 現在選択されているメールを取得
On Error Resume Next
Set email = Application.ActiveExplorer.Selection.Item(1)
On Error GoTo 0

If Not email Is Nothing Then
    Set attachments = email.Attachments
    senderEmail = email.SenderEmailAddress
    receivedDate = Format(email.ReceivedTime, "yyMMdd_HHmm")
    
    ' 添付ファイルを処理
    For i = 1 To attachments.Count
        Set attachment = attachments.Item(i)
        If Right(attachment.FileName, Len(sourceExtension)) = sourceExtension Then
            ' 添付ファイルの名前と保存先を設定
            newName = Left(senderEmail, 5) & "_" & receivedDate & ".zip"
            destinationPath = destinationFolder & "\" & newName
            
            ' 一時的なパスに添付ファイルを保存
            tempPath = destinationFolder & "\" & attachment.FileName
            attachment.SaveAsFile tempPath

            ' 添付ファイルの拡張子を変更して保存先フォルダに移動
            Name tempPath As destinationPath
        End If
    Next i
Else
    MsgBox "メールが選択されていません。"
End If

End Sub

@echo off
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$vpnName = '****';" ^
"$vpn = Get-VpnConnection -Name $vpnName -ErrorAction SilentlyContinue;" ^
"if ($vpn) { Connect-VpnConnection -Name $vpnName; Write-Host 'VPN 接続完了'; } else { Write-Host 'VPNが見つかりません'; }"

pause

@echo off
rem プロキシをONにする(1: ON, 0: OFF)
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?