Outlook';“保存文件”对话框?
我正在开发一个Outlook加载项,它需要Office特定的FileDialog与Sharepoint网站进行互操作;“公用文件”对话框没有互操作性。我知道Word和Excel在Globals.ThisAddIn.Application.Application下都有一个get\u fileDialog方法,但Outlook似乎没有。如何启动Outlook文件对话框?甚至可能吗?Outlook';“保存文件”对话框?,outlook,office-2007,outlook-2007,outlook-addin,Outlook,Office 2007,Outlook 2007,Outlook Addin,我正在开发一个Outlook加载项,它需要Office特定的FileDialog与Sharepoint网站进行互操作;“公用文件”对话框没有互操作性。我知道Word和Excel在Globals.ThisAddIn.Application.Application下都有一个get\u fileDialog方法,但Outlook似乎没有。如何启动Outlook文件对话框?甚至可能吗? 'Add a "Module". Then add the declarations like this to it.
'Add a "Module". Then add the declarations like this to it.
Option Explicit
Private Declare Function GetOpenFileName _
Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Function MyOpenFiledialog() As String
Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hwndOwner = Application.hWnd
'Set the application's instance
OFName.hInstance = Application.hInstance
'Select a filter
OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'create a buffer for the file
OFName.lpstrFile = Space$(254)
'set the maximum length of a returned file
OFName.nMaxFile = 255
'Create a buffer for the file title
OFName.lpstrFileTitle = Space$(254)
'Set the maximum length of a returned file title
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the title
OFName.lpstrTitle = "Open File - VB Forums.com"
'No flags
OFName.flags = 0
'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
MsgBox "File to Open: " + Trim$(OFName.lpstrFile)
MyOpenFiledialog = Trim$(OFName.lpstrFile)
Else
MsgBox "Cancel was pressed"
MyOpenFiledialog = vbNullString
End If
End Sub 'Usage:
Private Sub Command1_Click()
Text1.Text = MyOpenFiledialog
End Sub
如果您安装了COMDLG32.OCX(“Common Dialog ActiveX控件”),那么您可以使用它—这里用一个示例进行说明。(向下滚动屏幕截图“图2:不要尝试在Word中选择多个文件!”。Outlook的应用程序对象似乎不提供
FileDialog
。但是,如果您愿意使用Excel参考,一个简单的解决方法是:
Dim fd As FileDialog
Set fd = Excel.Application.FileDialog(msoFileDialogFolderPicker)
Dim folder As Variant
If fd.Show = -1 Then
For Each folder In fd.SelectedItems
Debug.Print "Folder:" & folder & "."
Next
End If
Private Sub multiEML2MSG()
Const PR_图标索引=&H10800003
将objPost设置为Outlook.PostItem
Dim objSafePost As Redemption.safepositem
将对象设置为Outlook.NameSpace
将objInbox设置为Outlook.Mapi文件夹
设置objNS=Outlook.GetNamespace(“MAPI”)
设置objInbox=objNS.GetDefaultFolder(olFolderInbox)
Set objPost=objInbox.Items.Add(OlItemType.olpositem)
设置objSafePost=New Redemption.safepositem
Dim xlObj作为Excel.Application
将fd设置为Office.FileDialog
Set xlObj=New Excel.Application
设置fd=xlObj.Application.FileDialog(msoFileDialogFolderPicker)
有fd
.Title=“选择您的PST文件”
.ButtonName=“好的”
显示
如果fd.SelectedItems.Count为0,则
xDirect$=fd.SelectedItems(1)和“\”
xFname$=Dir(xDirect$,7)
李茨尼克=1
执行xFname$“”
XPathEML=xDirect$&xFname$
XPathMSG=Replace(XPathML、.eml、.msg、.vbTextCompare)
打印XPath,替换(XPath、.eml、.msg、.vbTextCompare)
objPost.Save
objSafePost.Item=objPost
objSafePost.Import XPathEML,Redemption.RedemptionSaveAsType.olRFC822
objSafePost.MessageClass=“IPM.Note”
objSafePost.字段(PR_图标_索引)=无
objSafePost.SaveAs xpathmg,Outlook.OlSaveAsType.olMSG
xFname$=Dir
licznik=licznik+1
环
如果结束
以
xlObj.退出
Set xlObj=无
设置objSafePost=Nothing
Set objPost=Nothing
设置对象框=无
Set objNS=Nothing
端接头
Outlook不支持应用程序中的文件打开对话。另外,www.slipstick.com是Outlook开发者提供提示和代码的最佳网站。我可能应该提到我使用的是VSTO,而不是VBA。无论如何,我不认为创建自己的对话框会有所帮助,因为它需要Office对话框提供的真正特定的SharePoint功能。对我来说似乎不起作用(Outlook 2007)?我认为函数“MyOpenFiledialog()”以“End Sub”终止有一个小错误,但我将其更改为“End Function”,现在收到错误//运行时错误“438”:对象不支持此属性或方法//-按“DEBUG”将我带到行//of name.hwndoner=Application.hWnd///欢迎使用堆栈溢出!虽然这个代码片段可以解决这个问题,但它确实有助于提高文章的质量。请记住,您将在将来回答读者的问题,这些人可能不知道您的代码建议的原因。还请尽量不要用解释性注释挤满你的代码,这会降低代码和解释的可读性!
Dim fd As FileDialog
Set fd = Excel.Application.FileDialog(msoFileDialogFolderPicker)
Dim folder As Variant
If fd.Show = -1 Then
For Each folder In fd.SelectedItems
Debug.Print "Folder:" & folder & "."
Next
End If
Private Sub multiEML2MSG()
Const PR_ICON_INDEX = &H10800003
Dim objPost As Outlook.PostItem
Dim objSafePost As Redemption.SafePostItem
Dim objNS As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Set objNS = Outlook.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objPost = objInbox.Items.Add(OlItemType.olPostItem)
Set objSafePost = New Redemption.SafePostItem
Dim xlObj As Excel.Application
Dim fd As Office.FileDialog
Set xlObj = New Excel.Application
Set fd = xlObj.Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Select your PST File"
.ButtonName = "Ok"
.Show
If fd.SelectedItems.Count <> 0 Then
xDirect$ = fd.SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
licznik = 1
Do While xFname$ <> ""
XPathEML = xDirect$ & xFname$
XPathMSG = Replace(XPathEML, ".eml", ".msg", , , vbTextCompare)
Debug.Print XPath, Replace(XPath, ".eml", ".msg", , , vbTextCompare)
objPost.Save
objSafePost.Item = objPost
objSafePost.Import XPathEML, Redemption.RedemptionSaveAsType.olRFC822
objSafePost.MessageClass = "IPM.Note"
objSafePost.Fields(PR_ICON_INDEX) = none
objSafePost.SaveAs XPathMSG, Outlook.OlSaveAsType.olMSG
xFname$ = Dir
licznik = licznik + 1
Loop
End If
End With
xlObj.Quit
Set xlObj = Nothing
Set objSafePost = Nothing
Set objPost = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub