使用 powershell 或 VBA 编辑扩展文件属性?
Editing extended file properties using powershell or VBA?
有没有办法 edit/change 使用 powershell 的文件的扩展文件属性?特别是我想更改从 Outlook 导出的 .msg 文件的扩展文件属性。我在网上看到一个程序(专有代码),它保存一个具有扩展文件属性的 .msg 文件,以便可以在文件资源管理器中对其进行排序。在 .msg 上启用的扩展属性是有用的信息,例如接收日期、发件人等。
我一辈子都找不到在 VBA 或 powershell 中执行此操作的简单方法,我想知道是否有人有任何想法或解决方案。目前我已经创建了一个宏,它只是将信息保存在文件名中,但将其放在扩展文件属性中会更有用。
最让我沮丧的是,有人明明这样做了,但我不知道怎么做。我原以为这会很简单。唉。
编辑:请查看我当前的代码
Public Sub SaveMessageAsMsg()
Dim xMail As Outlook.MailItem
Dim xObjItem As Object
Dim xPath As String
Dim xDtDate As Date
Dim xName, xFileName As String
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xFolder = xShell.BrowseForFolder(0, "Select a folder:", 0, "C:\Users\" & Environ("UserName") & "ANON VARIABLE")
If Not TypeName(xFolder) = "Nothing" Then
Set xFolderItem = xFolder.self
xFileName = xFolderItem.Path & "\"
Else
xFileName = ""
Exit Sub
End If
For Each xObjItem In Outlook.ActiveExplorer.Selection
If xObjItem.Class = olMail Then
Set xMail = xObjItem
SenderName = xMail.SenderName
xName = xMail.Subject
xDtDate = xMail.ReceivedTime
xName = Replace(Format(xDtDate, "yyyy-mm-dd ", vbUseSystemDayOfWeek, _
vbUseSystem) & " @ " & Format(xDtDate, "hh:mm:ss", _
vbUseSystemDayOfWeek, vbUseSystem) & " - " & SenderName & " - " & xName & ".msg", ":", ".")
Dim RegEx As Object
Set RegEx = CreateObject("VBScript.RegExp")
With RegEx
.Pattern = "[\/\*\?""<>\|]"
.Global = True
ValidName = .Replace(xName, "")
End With
xPath = xFileName + ValidName
xMail.SaveAs xPath, olMSG
End If
Next
End Sub
您在 VBA 或 Outlook 对象模型中无法轻松做到这一点:这些额外的属性必须在 MSG 文件使用的 OLE 存储级别上设置。
如果使用 Redemption(我是它的作者)是一个选项,它会公开 olMsgWithSummary
格式(类似于 OOM 中的 olMsg
和 olMsgUnicode
)你需要什么。下面的脚本保存当前选择的 Outlook 邮件:
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set oMsg = Application.ActiveExplorer.Selection(1)
set rMsg = Session.GetRDOObjectFromOutlookObject(oMsg)
rMsg.SaveAs "c:\temp\ExtraProps.msg", 1035 '1035 is olMsgWithSummary
您上面的脚本需要以下内容(超出我的想象):
Public Sub SaveMessageAsMsg()
Dim xMail As Outlook.MailItem
Dim xObjItem As Object
Dim xPath As String
Dim xDtDate As Date
Dim rSession As Object
Dim rSession As Object
Dim xName, xFileName As String
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xFolder = xShell.BrowseForFolder(0, "Select a folder:", 0, "C:\Users\" & Environ("UserName") & "ANON VARIABLE")
If Not TypeName(xFolder) = "Nothing" Then
Set xFolderItem = xFolder.self
xFileName = xFolderItem.Path & "\"
Else
xFileName = ""
Exit Sub
End If
set rSession = CreateObject("Redemption.RDOSession")
rSession.MAPIOBJECT = Outlook.Session.MAPIOBJECT
For Each xObjItem In Outlook.ActiveExplorer.Selection
If xObjItem.Class = olMail Then
Set xMail = xObjItem
SenderName = xMail.SenderName
xName = xMail.Subject
xDtDate = xMail.ReceivedTime
xName = Replace(Format(xDtDate, "yyyy-mm-dd ", vbUseSystemDayOfWeek, _
vbUseSystem) & " @ " & Format(xDtDate, "hh:mm:ss", _
vbUseSystemDayOfWeek, vbUseSystem) & " - " & SenderName & " - " & xName & ".msg", ":", ".")
Dim RegEx As Object
Set RegEx = CreateObject("VBScript.RegExp")
With RegEx
.Pattern = "[\/\*\?""<>\|]"
.Global = True
ValidName = .Replace(xName, "")
End With
xPath = xFileName + ValidName
set rMsg = rSession.GetRDOObjectFromOutlookObject(xMail)
rMsg.SaveAs xPath, 1035
End If
Next
End Sub
有没有办法 edit/change 使用 powershell 的文件的扩展文件属性?特别是我想更改从 Outlook 导出的 .msg 文件的扩展文件属性。我在网上看到一个程序(专有代码),它保存一个具有扩展文件属性的 .msg 文件,以便可以在文件资源管理器中对其进行排序。在 .msg 上启用的扩展属性是有用的信息,例如接收日期、发件人等。
我一辈子都找不到在 VBA 或 powershell 中执行此操作的简单方法,我想知道是否有人有任何想法或解决方案。目前我已经创建了一个宏,它只是将信息保存在文件名中,但将其放在扩展文件属性中会更有用。
最让我沮丧的是,有人明明这样做了,但我不知道怎么做。我原以为这会很简单。唉。
编辑:请查看我当前的代码
Public Sub SaveMessageAsMsg()
Dim xMail As Outlook.MailItem
Dim xObjItem As Object
Dim xPath As String
Dim xDtDate As Date
Dim xName, xFileName As String
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xFolder = xShell.BrowseForFolder(0, "Select a folder:", 0, "C:\Users\" & Environ("UserName") & "ANON VARIABLE")
If Not TypeName(xFolder) = "Nothing" Then
Set xFolderItem = xFolder.self
xFileName = xFolderItem.Path & "\"
Else
xFileName = ""
Exit Sub
End If
For Each xObjItem In Outlook.ActiveExplorer.Selection
If xObjItem.Class = olMail Then
Set xMail = xObjItem
SenderName = xMail.SenderName
xName = xMail.Subject
xDtDate = xMail.ReceivedTime
xName = Replace(Format(xDtDate, "yyyy-mm-dd ", vbUseSystemDayOfWeek, _
vbUseSystem) & " @ " & Format(xDtDate, "hh:mm:ss", _
vbUseSystemDayOfWeek, vbUseSystem) & " - " & SenderName & " - " & xName & ".msg", ":", ".")
Dim RegEx As Object
Set RegEx = CreateObject("VBScript.RegExp")
With RegEx
.Pattern = "[\/\*\?""<>\|]"
.Global = True
ValidName = .Replace(xName, "")
End With
xPath = xFileName + ValidName
xMail.SaveAs xPath, olMSG
End If
Next
End Sub
您在 VBA 或 Outlook 对象模型中无法轻松做到这一点:这些额外的属性必须在 MSG 文件使用的 OLE 存储级别上设置。
如果使用 Redemption(我是它的作者)是一个选项,它会公开 olMsgWithSummary
格式(类似于 OOM 中的 olMsg
和 olMsgUnicode
)你需要什么。下面的脚本保存当前选择的 Outlook 邮件:
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set oMsg = Application.ActiveExplorer.Selection(1)
set rMsg = Session.GetRDOObjectFromOutlookObject(oMsg)
rMsg.SaveAs "c:\temp\ExtraProps.msg", 1035 '1035 is olMsgWithSummary
您上面的脚本需要以下内容(超出我的想象):
Public Sub SaveMessageAsMsg()
Dim xMail As Outlook.MailItem
Dim xObjItem As Object
Dim xPath As String
Dim xDtDate As Date
Dim rSession As Object
Dim rSession As Object
Dim xName, xFileName As String
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xFolder = xShell.BrowseForFolder(0, "Select a folder:", 0, "C:\Users\" & Environ("UserName") & "ANON VARIABLE")
If Not TypeName(xFolder) = "Nothing" Then
Set xFolderItem = xFolder.self
xFileName = xFolderItem.Path & "\"
Else
xFileName = ""
Exit Sub
End If
set rSession = CreateObject("Redemption.RDOSession")
rSession.MAPIOBJECT = Outlook.Session.MAPIOBJECT
For Each xObjItem In Outlook.ActiveExplorer.Selection
If xObjItem.Class = olMail Then
Set xMail = xObjItem
SenderName = xMail.SenderName
xName = xMail.Subject
xDtDate = xMail.ReceivedTime
xName = Replace(Format(xDtDate, "yyyy-mm-dd ", vbUseSystemDayOfWeek, _
vbUseSystem) & " @ " & Format(xDtDate, "hh:mm:ss", _
vbUseSystemDayOfWeek, vbUseSystem) & " - " & SenderName & " - " & xName & ".msg", ":", ".")
Dim RegEx As Object
Set RegEx = CreateObject("VBScript.RegExp")
With RegEx
.Pattern = "[\/\*\?""<>\|]"
.Global = True
ValidName = .Replace(xName, "")
End With
xPath = xFileName + ValidName
set rMsg = rSession.GetRDOObjectFromOutlookObject(xMail)
rMsg.SaveAs xPath, 1035
End If
Next
End Sub