Je suis en train de travailler sur un complément Outlook qui nécessite l'interface de FileDialog spécifique à Office pour interopérer avec un site Sharepoint; la boîte de dialogue de fichier commun n'a pas l'interopérabilité. Je sais que Word et Excel ont une méthode get_fileDialog sous Globals.ThisAddIn.Application.Application, mais Outlook ne semble pas. Comment lancer un fichier OutlookDialog? Est-ce même possible?Où Outlook sauvegarde-t-il FileDialog?
Répondre
Si vous avez COMDLG32.OCX ("Common Dialog ActiveX Control") installé, vous pouvez l'utiliser - il est expliqué ici, avec un exemple. (Faites défiler vers le bas juste après la capture d'écran intitulée "FIGURE 2: N'essayez pas de sélectionner plus d'un fichier dans Word!").
'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
Il semble que l'objet Application d'Outlook n'offre pas FileDialog
. Mais une solution de contournement simple, si vous êtes prêt à avoir une référence Excel, est:
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
Bienvenue dans Stack Overflow! Bien que cet extrait de code puisse résoudre la question, [y compris une explication] (// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) aide vraiment à améliorer la qualité de votre message. Rappelez-vous que vous répondez à la question pour les lecteurs dans le futur, et que ces personnes pourraient ne pas connaître les raisons de votre suggestion de code. Essayez également de ne pas surcharger votre code avec des commentaires explicatifs, ceci réduit la lisibilité du code et des explications! – kayess
- 1. Utiliser un FileDialog pour choisir un fichier d'une certaine extension
- 2. outlook programming
- 3. Outlook 2007 plugin
- 4. Intégration de VSTO Outlook - Événement d'arrêt Outlook pour la synchronisation
- 5. Envoi de demandes de réunion Outlook sans Outlook?
- 6. Où Outlook stocke-t-il les fichiers PST qui sont montés?
- 7. Test des plugins Outlook
- 8. filtre rendez-vous Outlook
- 9. Outlook Express Add-in
- 10. Outlook Interop, Mail Format
- 11. Démarrer Outlook avec C#
- 12. Format iCalendar (Outlook 2007)
- 13. API de réplication Outlook
- 14. Outlook Redemption: GetNamesFromIDs
- 15. JS Calendrier contrôle Outlook
- 16. Tester Outlook Additifs VSTO
- 17. Outlook View Control
- 18. Extensions Outlook 2003
- 19. css background Outlook 2007
- 20. Comment filtrer un objet de rapport lors de l'enregistrement via FileDialog dans MS Access
- 21. Ajouter TextboxCell personnalisé à un contrôle DataGridView qui contient un bouton pour ouvrir le FileDialog
- 22. Approbation de workflow Sharepoint via Outlook email
- 23. Créer automatiquement rendez-vous Outlook
- 24. MS Outlook Integration utilisant C#
- 25. Office (en particulier Outlook) addins
- 26. Python Outlook 2007 COM primer
- 27. Outils de complément Outlook api
- 28. Installer Outlook addin et exe
- 29. Outlook 2007 MailItem Info - lent
- 30. itération via rendez-vous Outlook
Outlook ne prend pas en charge le dialogue FileOpen hors application. Aussi www.slipstick.com est le meilleur site de développeurs Outlook pour les conseils et le code. – MaSuGaNa
Je devrais probablement avoir mentionné que j'utilise VSTO, pas VBA. Dans tous les cas, je ne pense pas que ma propre boîte de dialogue serait utile car elle nécessitait la fonctionnalité SharePoint vraiment spécifique fournie par la boîte de dialogue Office. – benmatth
Ne semble pas fonctionner pour moi (Outlook 2007)? Je pense qu'il y a un Typo mineur en ce que la fonction 'MyOpenFiledialog()' est terminée avec un 'End Sub' - mais j'ai changé cela en 'End Function' et maintenant recevez l'erreur // Erreur d'exécution '438': Object ne supporte pas cette propriété ou cette méthode // - appuyer sur 'DEBUG' m'amène à la ligne //OFName.hwndOwner = Application.hWnd // – monojohnny