How to Open File Selector dialog in VBA

  • Thread starter Thread starter Peter Hibbs
  • Start date Start date
P

Peter Hibbs

In Outlook 2003 I have added a custom button to the tool-bar which
runs some VBA code so that the user can save an email as a .msg file
to disk. What I want to do is - when the user clicks the button is to
open the standard Office File Selector dialog form so that the user
can then save the email file to a location of their choice.

Does anyone have some code to open a dialog and return the full
pathname and filename that the user selects. I don't really want to
have to create a new form in Outlook just for this.

Peter Hibbs.
 
That dialog isn't available from Outlook. You can automate it by setting up
automation for Word or Excel or some other app that does expose that dialog.
You could also use the Win32 API common dialog from VBA code, but that's
somewhat more difficult to work with. There are samples for using the common
dialog from VB6, which would be almost identical to using it from VBA, at
www.vbaccelerator.com.
 
Thanks Ken. As you say, the code on the VB6 Web site is more complex
than I want to get into for this project. I will have to think of some
other way to do what I want.

Peter Hibbs.
 
Use:

Function GetCurrentItem() As Object
On Error Resume Next
Select Case TypeName(Outlook.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = Outlook.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = Outlook.ActiveInspector.CurrentItem
Case Else
End Select
End Function

Sub savemailitem()
Dim objitem As Object
Set objitem = GetCurrentItem()
If objitem.Class = 43 Then
SendKeys "%fa"
End If
End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
Doug,

Thanks for the code, I will have a play with it and see if will do
what my client wants.

Peter Hibbs.
 
Back
Top