Outlook 2003: How to show a filedialog from Outlook
For some reason, Outlook does not support filedialogs (Application.FileDialog) while other applications do (Excel, Word). I have seen solutions to this problem that use automation to create a Word or Excel object and then use the filedialog property of the Word or Excel object to display a the filedialog (setting objWORD/objEXCEL.width = 0 and objWORD/objEXCEL.Height = 0). I have run into several issues when using this method and I am wondering if anyone knows how to display a filedialog through Outlook. Does Windows have a filedialog that can be displayed?
Thanks in advance for the help!
Re: Outlook 2003: How to show a filedialog from Outlook
What are you trying to do? Is this using a UserForm or Outlook Form or VBA/Add-In code?
If your looking for a file browse dialog you can use APIs in a module of VBA code to manually generate a commondialog dialog.
Re: Outlook 2003: How to show a filedialog from Outlook
Yes, I'm looking for a file browse dialog. I'm not all that familiar with using APIs. I'm guessing I would use the COMDLG32.dll?? Anything you could show me would be AWESOME!
Thanks for the help, robdog!
Re: Outlook 2003: How to show a filedialog from Outlook
Heres a link with several examples for whatever type of operation you need.
http://www.allapi.net/apilist/GetOpenFileName.shtml
Re: Outlook 2003: How to show a filedialog from Outlook
Here is some code from the URL you provided me:
VB Code:
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Do I put this in a standard module? How do I call it?
Re: Outlook 2003: How to show a filedialog from Outlook
Yes, In your VBA IDE you have a ThisOutlookSession class only. You need to right click the project and click "Add Module". This will add a new standard module to your VBA Project. In this new module you can add the API and needed code for the function.
Re: Outlook 2003: How to show a filedialog from Outlook
After right-clicking on ThisOutlookSession, I have the option to "Insert..." a User Form, Module, or Class Module. Which one is it? I have no clue what code to add to it. I'm sure someone has done this before, I can't be the only person who has needed a file dialog in Outlook.
There is some code here that uses APIs, but I have no clue how to call it. Would I just type GetOpenFileName or something like that?
Re: Outlook 2003: How to show a filedialog from Outlook
Yes, the link I posted. Did you look at the code xamples at the bottom of the page?
Add a "Module". Then add the declarations like this to it.
VB Code:
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
VB Code:
'Usage:
Private Sub Command1_Click()
Text1.Text = MyOpenFiledialog
End Sub
Re: Outlook 2003: How to show a filedialog from Outlook
Before I get into my debug issues... Has anyone ever told you that you are the man? Because if not, then here it is...
RobDog is the man!!!
Ok, now to my probs...
The Application object doesn't have a "hWnd" or "hInstance" property.
VB Code:
'Set the parent window
OFName.hwndOwner = Application.hWnd
'Set the application's instance
OFName.hInstance = Application.hInstance
There is however an Application.Parent property... would that work instead of .hWnd? Are the .hWnd and .hInstance props only available in VB6?
Re: Outlook 2003: How to show a filedialog from Outlook
It seems to work with those properties omitted. Is there a property of OPENFILENAME that would allow me to set the text on the buttons? Instead of "Open", I would like it to be "OK". Something like:
VB Code:
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
[COLOR=Red][I]cmdOKText As String[/I][/COLOR]
.
.
.
End Type
' And set this property with:
Dim OFName As OPENFILENAME
OFName.cmdOKText = "OK"
Where did you get the list of available settings?
Re: Outlook 2003: How to show a filedialog from Outlook
:D Thanks.
Check out the link in post #4. You should also download the API Viewer utility from all api as it contains almost all the API definitions and constants.
Re: Outlook 2003: How to show a filedialog from Outlook