使用VBA在Outlook中将文件添加为附件时,如何使打开的文件夹对话框窗口成为活动窗口? [英] When adding a file as attachment in Outlook using VBA how can I make the open folder dialog window the active window?

查看:81
本文介绍了使用VBA在Outlook中将文件添加为附件时,如何使打开的文件夹对话框窗口成为活动窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我有可用的代码,但是用于添加文件的浏览器会在后台显示.情况还不错,但是当发生这种情况时,它会冻结前景,从而难以快速上手.

我试图弄清楚如何使弹出式浏览器显示在所有内容的顶部,从而不会被隐藏.同样,它的速度也非常慢,因此,如果有一种更有效的方法,那就太好了.到目前为止,这就是我所拥有的.

 选项显式私人子AttachmentFile()视作对象昏暗邮件作为对象暗淡FD作为对象将vrtSelectedItem变暗为变体设置oLook = CreateObject("Outlook.Application")设置oMail = oLook.CreateItem(0)设置FD = Excel.Application.FileDialog(3)使用oMailFD.AllowMultiSelect = TrueFD.Filters.ClearFD.Filters.Add所有文件","*.*"FD.InitialFileName ="\\ ad \ dfs \ Shared Data \"如果FD.Show = True,则对于FD.SelectedItems中的每个vrtSelectedItem.附件.添加vrtSelectedItem下一个万一.展示结束于设置FD =否设置oMail = Nothing设置oLook = Nothing结束子 

解决方案

尽管Outlook中没有 FileDialog 对象,但是您可以模拟使用 ExecuteMso 按下按钮.

要打开"Outlook插入文件"对话框,请按AttachFile按钮:

  Private子ExecuteMso_AttachFile()Dim currItem作为对象关于错误继续设置currItem = ActiveInspector.currentItem出错时转到0如果currItem什么都没有,则设置currItem = CreateItem(olMailItem)currItem.Display'将鼠标悬停在您将添加为按钮的图标上'在ExecuteMso中使用的IdMso是显示的文本的最后一部分.ActiveInspector.CommandBars.ExecuteMso("AttachFile")结束子 

OK so I have working code, however the browser for adding files shows up in the background. This wouldn't be so bad but it freezes outlook when this happens making it difficult to get to quickly.

I'm trying to figure out how to make the popup browser show on top of everything so it's not buried. Also it is incredibly slow so if there is a more efficient way, that would be great as well. Here is what I have so far.

Option Explicit
Private Sub AttachmentFile()
Dim oLook As Object
Dim oMail As Object
Dim FD As Object
Dim vrtSelectedItem As Variant

    Set oLook = CreateObject("Outlook.Application")
    Set oMail = oLook.CreateItem(0)
    Set FD = Excel.Application.FileDialog(3)

    With oMail

            FD.AllowMultiSelect = True
            FD.Filters.Clear
            FD.Filters.Add "All Files", "*.*"
            FD.InitialFileName = "\\ad\dfs\Shared Data\"

            If FD.Show = True Then
                  For Each vrtSelectedItem In FD.SelectedItems
                  .Attachments.Add vrtSelectedItem
                    Next
            End If
            .Display
    End With
    Set FD = Nothing
    Set oMail = Nothing
    Set oLook = Nothing

End Sub

解决方案

Although there is no FileDialog object in Outlook you may simulate pressing a button with ExecuteMso.

To open the Outlook Insert File dialog press the AttachFile button:

Private Sub ExecuteMso_AttachFile()

    Dim currItem As Object

    On Error Resume Next
    Set currItem = ActiveInspector.currentItem
    On Error GoTo 0

    If currItem Is Nothing Then Set currItem = CreateItem(olMailItem)

    currItem.Display

    ' Hover over the icon that you would add as a button
    ' The IdMso to use in ExecuteMso is the last part of the text displayed.
    ActiveInspector.CommandBars.ExecuteMso ("AttachFile")

End Sub

这篇关于使用VBA在Outlook中将文件添加为附件时,如何使打开的文件夹对话框窗口成为活动窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆