我尝试在我的Outlook中添加功能(使用VBA,我认为最简单)添加一个简单的文件对话框,该对话框选择所选文件的路径并将其作为超链接添加到电子邮件正文中。
这个想法是让网络文件在同事之间共享,而不是将它们附加到电子邮件中,但同样容易。
这是我的代码到目前为止,我甚至无法打开对话框,而且我已经很好地了解了COMDLG32.ocx
,到目前为止,我可以'}似乎让任何事情都有效。
Sub Main2()
Dim CDLG As Object
Set CDLG = CreateObject("MSComDlg.CommonDialog")
With CDLG
.DialogTitle = "Get me a File!"
.Filter = _
"Documents|*.doc|Templates|*.dot|Text Files|*.txt"
.ShowOpen
MsgBox .FileName
End With
Set CDLG = Nothing
End Sub
先谢谢,希望有人能告诉我这是怎么做的!
只为那些需要它的人; OS Windows 10,Office 2010 H& B(是的,我知道它已经过时了:))
答案 0 :(得分:1)
似乎没有直接的方式在FileDialog
中打开Outlook 2010 VBA
。
以下宏(受related post启发)利用Excel
来规避这一点:
Public Function promptFileName(title As String, filter As String) As String
' requires project reference to "Microsoft Excel 14.0 Object Library"
Dim xlObj As Excel.Application
Dim fd As Office.FileDialog
Dim name As String
Dim vItem As Variant
Dim filterArray() As String
Dim i As Integer
Set xlObj = New Excel.Application
xlObj.Visible = False
Set fd = xlObj.Application.FileDialog(msoFileDialogOpen)
name = ""
With fd
.title = title
.ButtonName = "Ok"
.Filters.Clear
filterArray = Split(filter, "|")
For i = LBound(filterArray) To UBound(filterArray) - 1 Step 2
.Filters.Add filterArray(i), filterArray(i + 1), 1 + i \ 2
Next i
If .Show = -1 Then
For Each vItem In .SelectedItems
name = vItem
Exit For
Next
End If
End With
xlObj.Quit
Set xlObj = Nothing
promptFileName = name
End Function
Private Sub testPromptFile
Dim name as String
name = promptFileName("a test", "Text Files (*.txt)|*.txt|All Files (*.*)|*.*")
MsgBox name
End Sub
Outlook 2013
及以后为此目的提供了Office.FileDialog
类。
答案 1 :(得分:0)
您可以按Outlook VBA按钮。
Sub ExecuteMso_strId()
Dim objItem As Object
Dim strId As String
' Text appears when hovering over icon
' when adding buttons to a Quick Access toolbar or a ribbon
strId = "HyperlinkInsert"
On Error Resume Next
Set objItem = ActiveInspector.currentItem
On Error GoTo 0
If Not objItem Is Nothing Then
ActiveInspector.CommandBars.ExecuteMso (strId)
Else
ActiveExplorer.CommandBars.ExecuteMso (strId)
End If
End Sub
使用此功能,您无法像使用Excel一样访问参数。