Results 1 to 12 of 12

Thread: Outlook 2003: How to show a filedialog from Outlook

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    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!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    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!

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Re: Outlook 2003: How to show a filedialog from Outlook

    Here is some code from the URL you provided me:

    VB Code:
    1. 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?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    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?

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. Option Explicit
    2.  
    3. Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    4.  
    5. Private Type OPENFILENAME
    6.     lStructSize As Long
    7.     hwndOwner As Long
    8.     hInstance As Long
    9.     lpstrFilter As String
    10.     lpstrCustomFilter As String
    11.     nMaxCustFilter As Long
    12.     nFilterIndex As Long
    13.     lpstrFile As String
    14.     nMaxFile As Long
    15.     lpstrFileTitle As String
    16.     nMaxFileTitle As Long
    17.     lpstrInitialDir As String
    18.     lpstrTitle As String
    19.     flags As Long
    20.     nFileOffset As Integer
    21.     nFileExtension As Integer
    22.     lpstrDefExt As String
    23.     lCustData As Long
    24.     lpfnHook As Long
    25.     lpTemplateName As String
    26. End Type
    27.  
    28. Public Function MyOpenFiledialog() As String
    29.  
    30.     Dim OFName As OPENFILENAME
    31.     OFName.lStructSize = Len(OFName)
    32.     'Set the parent window
    33.     OFName.hwndOwner = Application.hWnd
    34.     'Set the application's instance
    35.     OFName.hInstance = Application.hInstance
    36.     'Select a filter
    37.     OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
    38.     'create a buffer for the file
    39.     OFName.lpstrFile = Space$(254)
    40.     'set the maximum length of a returned file
    41.     OFName.nMaxFile = 255
    42.     'Create a buffer for the file title
    43.     OFName.lpstrFileTitle = Space$(254)
    44.     'Set the maximum length of a returned file title
    45.     OFName.nMaxFileTitle = 255
    46.     'Set the initial directory
    47.     OFName.lpstrInitialDir = "C:\"
    48.     'Set the title
    49.     OFName.lpstrTitle = "Open File - VB Forums.com"
    50.     'No flags
    51.     OFName.flags = 0
    52.  
    53.     'Show the 'Open File'-dialog
    54.     If GetOpenFileName(OFName) Then
    55.         MsgBox "File to Open: " + Trim$(OFName.lpstrFile)
    56.         MyOpenFiledialog = Trim$(OFName.lpstrFile)
    57.     Else
    58.         MsgBox "Cancel was pressed"
    59.         MyOpenFiledialog = vbNullString
    60.     End If
    61.  
    62. End Sub
    VB Code:
    1. 'Usage:
    2. Private Sub Command1_Click()
    3.     Text1.Text = MyOpenFiledialog
    4. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    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:
    1. 'Set the parent window
    2.     OFName.hwndOwner = Application.hWnd
    3.     'Set the application's instance
    4.     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?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    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:
    1. Private Type OPENFILENAME
    2.     lStructSize As Long
    3.     hwndOwner As Long
    4.     hInstance As Long
    5.     lpstrFilter As String
    6.     [COLOR=Red][I]cmdOKText As String[/I][/COLOR]
    7.            .
    8.            .
    9.            .
    10. End Type
    11.  
    12. ' And set this property with:
    13.  
    14.     Dim OFName As OPENFILENAME
    15.     OFName.cmdOKText = "OK"

    Where did you get the list of available settings?

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook 2003: How to show a filedialog from Outlook

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: Outlook 2003: How to show a filedialog from Outlook

    Thanks RobDog888

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width