Ich arbeite an einem Outlook-Add-In, das den Office-spezifischen FileDialog für die Zusammenarbeit mit einer Sharepoint-Site benötigt. Der allgemeine Dateidialog hat keine Interoperabilität. Ich weiß, dass sowohl Word als auch Excel eine get_fileDialog-Methode unter Globals.ThisAddIn.Application.Application haben, aber Outlook nicht scheint. Wie starte ich einen Outlook FileDialog? Ist es überhaupt möglich?Wo ist der FileDialog von Outlook?
Antwort
Wenn Sie COMDLG32.OCX haben ("Common Dialog ActiveX Control") installiert haben, dann können Sie diese verwenden - es ist hier erklärt, mit einem Beispiel. (Scrollen Sie direkt nach dem Screenshot mit der Überschrift "ABBILDUNG 2: Versuchen Sie nicht, mehr als eine Datei in Word auszuwählen!").
'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
Public Sub TestFileDialog()
Dim otherObject As Excel.Application
Dim fdFolder As office.FileDialog
Set otherObject = New Excel.Application
otherObject.Visible = False
Set fdFolder = otherObject.Application.FileDialog(msoFileDialogFolderPicker)
fdFolder.Show
Debug.Print fdFolder.SelectedItems(1)
otherObject.Quit
Set otherObject = Nothing
End Sub
Es scheint, dass Outlook Application-Objekt FileDialog
nicht bietet. Aber eine einfache Abhilfe, wenn Sie bereit sind, eine Excel-Referenz haben, ist:
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
Willkommen bei Stack Overflow! Während dieser Code-Schnipsel, die Frage lösen kann, [einschließlich einer Erklärung] (// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) wirklich hilft, die Qualität Ihrer Post zu verbessern. Denken Sie daran, dass Sie die Frage für Leser in der Zukunft beantworten, und diese Leute könnten die Gründe für Ihren Codevorschlag nicht kennen. Bitte versuchen Sie auch nicht, Ihren Code mit erklärenden Kommentaren zu füllen, dies reduziert die Lesbarkeit sowohl des Codes als auch der Erklärungen! – kayess
- 1. Benutzerdefinierte FileDialog in QML
- 2. FileDialog-Ordner einschränken
- 3. FileDialog DoubleClick Verhalten
- 4. Wie sagen Outlook, wo Bilddateien sind?
- 5. Java FileDialog programmgesteuert Größe einstellen
- 6. Wo ist der Speicherort von Microsoft.Sharepoint.dll
- 7. Datenkorruption: Wo ist der Fehler?
- 8. Wo ist der yiic Befehl?
- 9. Wo ist der .NET-native?
- 10. Speichern/Organisieren/Suchen von Outlook E-Mail außerhalb von Outlook
- 11. Präsentation der globalen Adressliste von Outlook
- 12. Wo ist der Chocolatey Installationspfad?
- 13. Wo ist der versteckte Parameter?
- 14. Wo ist der: Befehlsverlauf gespeichert?
- 15. Wo ist der TestDriven.NET-Optionsbereich?
- 16. Wo ist der Null-Terminierungsfehler?
- 17. Java FileDialog Auswählen von Verzeichnissen: Nur Mac OSX?
- 18. Wo ist der Inhalt der Nachrichtenwarteschlange gespeichert?
- 19. SWT Filedialog öffnen in Home-Ordner
- 20. Standardisieren eines Ordners für FileDialog in VBA
- 21. Get kopierten Outlook-Anhang aus der Zwischenablage in Outlook 2016
- 22. Wie filtert man den Dateityp in FileDialog?
- 23. Wo können größere Daten für Outlook Web App gespeichert werden?
- 24. Wo speichert Outlook, welche PST-Dateien angehängt sind?
- 25. Outlook-MAPI-Sitzungsausnahme bei geschlossener Outlook-Schnittstelle
- 26. Outlook-Add-In, wo Konfiguration zu speichern, C#
- 27. Wie öffne ich eine Outlook .msg-Datei von meiner Festplatte, die NICHT in Outlook ist?
- 28. Wo ist die Speicherbelegung der Variable "__this_module"?
- 29. Azure Mobile-Dienst: wo ist der Anwendungsschlüssel
- 30. Wo ist der Linux-Kernel-Quellstartpunkt?
Outlook nicht unterstützt Fileopen Dialoge off-Anwendung. Auch www.slipstick.com ist die beste Outlook-Entwickler-Website für Tipps und Code. – MaSuGaNa
Ich hätte wahrscheinlich erwähnen sollen, dass ich VSTO verwende, nicht VBA. Auf jeden Fall glaube ich nicht, dass mein eigenes Dialogfeld helfen würde, da es die wirklich spezifische SharePoint-Funktionalität benötigte, die das Office-Dialogfeld zur Verfügung stellte. – benmatth
Scheint für mich nicht zu funktionieren (Outlook 2007)? Ich denke, es gibt einen kleinen Tippfehler darin, dass die Funktion 'MyOpenFiledialog()' mit einem 'End Sub' beendet wird - aber ich habe dies in 'End Function' geändert und erhalte nun den Fehler // Laufzeitfehler '438': Object unterstützt diese Eigenschaft oder Methode nicht // - Drücken von 'DEBUG' führt mich zur Zeile //OFName.hwndOwner = Anwendung.hWnd // – monojohnny