cmwade77 发表于 2018-11-6 11:35:10

展望VBA (365) vs 2010

我开发了一个简短的宏,允许我的365用户将电子邮件保存到项目文件夹。 我有2个用户仍然在2010年,我无法弄清楚为什么代码不起作用。 我以为这是一个参考或同样容易的东西,但没有运气。 这是代码,如果有人有一个想法
Sub SaveACopy() 'ByVal Item As Object)'Item As Object
    Const olMsg As Long = 3
    Dim m As MailItem
    Dim strPath As String
   Set m = GetCurrentItem
    If TypeName(m)"MailItem" Then Exit Sub
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = False
Dim fd As Office.FileDialog
Set fd = xlApp.Application.FileDialog(msoFileDialogFolderPicker)
Dim selectedItem As Variant
If fd.Show = -1 Then
    For Each selectedItem In fd.SelectedItems
      Debug.Print selectedItem
      strPath = selectedItem
    Next
End If
Set fd = Nothing
    xlApp.Quit
Set xlApp = Nothing
Dim strSubject As String
strSubject = m.Subject
strSubject = Replace(strSubject, ":", "")
'strPath = """" & strPath
strPath = strPath & "\" & strSubject
strPath = strPath & " " & Format(Now(), "ddmmmyyyy-hhNNss") '"yyyy-mm-dd-hhnnss"    YYYY-mm-dd
strPath = strPath & ".msg"
strPath = strPath '& """"
m.SaveAs strPath, olMsg
m.Close olDiscard
End Sub
'Set objItem = objApp.ActiveExplorer.Selection.Item(1)
Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
      Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
      Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
    Set objApp = Nothing
End Function

**** Hidden Message *****

kirby 发表于 2018-11-6 19:52:47

不幸的是,我不知道这个问题的答案,但非常方便的小程序。

kirby 发表于 2018-11-9 12:52:29


我们没有Outlook 2010了,所以无法检查。
我使用类似的程序来保存消息或编写带有ISO 8601日期时间代码(YYYY-MM-DD_Thhnn)的pdf,这些代码大多是从www.slipstick.com代码片段中抄袭来的。这些从2007年移植到2010年,2013年移植到365年,没有变化。
一个持续的问题是超过Windows 255字符路径和文件名长度(特别是当保存到我们已经太长的网络项目文件夹到深度嵌套的子文件夹中时)。简单的修复,如果你不介意截断消息文件名。
也许检查应用程序“Inspector”在2010年是否有效。
不是很有帮助,抱歉...
页: [1]
查看完整版本: 展望VBA (365) vs 2010