More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

forum 16-Jan-2018 11:28

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

    Page [ 1 2 3 Next >> ]  
 Code Essentials Printer Friendly Version
Beginner’s section on how to work in the VBA environment, how to work with functions and expressions – generally not specific to Outlook
This works in Access - can someone help me convert this over to vbscript for a Outlook form? This opens up the find file box and allows you to browse for it.

Sub cmdFindFile_Click()
Dim cdlg
Dim lngFormName
Dim lngAppInstance
Dim strInitDir
Dim strFileFilter
Dim lngResult
lngFormName = Me.hwnd
lngAppInstance = Application.hWndAccessApp
strInitDir = "C:\My Documents\"
strFileFilter = "Access Databases (*.mdb, *.mde)" & Chr(0) & "*.mdb; *.mde" & Chr(0)
lngResult = cdlg.OpenFileDialog(lngFormName, lngAppInstance, strInitDir, strFileFilter)

If cdlg.GetStatus = True Then
    Me.txtTo = Trim(cdlg.GetName)
    'MsgBox "You selected file: " & cdlg.GetName
    MsgBox "No file selected."
End If
End Sub

  18-Jan-2005  16:43
  19-Jan-2005  09:36   
What is cdlg? A common dialog control? For starters, you'd have to add that control to your Outlook form and use the proper syntax to access it as an object -- see
  19-Jan-2005  13:08   
This works great!! No need to Word or Excel.

Sub cmdFileTest_Click()
   On Error Resume Next
    Dim strBFF
    Dim objSHL
    Set objSHL = CreateObject("Shell.Application")
    Dim objBFF
    Set objBFF = objSHL.BrowseForFolder(&H0,"OpenFile",&H4031,&H0011)
    strBFF = objBFF.ParentFolder.ParseName(objBFF.Title).Path

    MsgBox strBFF

    Set objBFF = Nothing
    Set objSHL = Nothing
End Sub
  19-Jan-2005  17:06   
Cool and very close! Unfortunately, objBFF is Empty for me on Win XP if I select a file. I'll continue playing around with it.
  20-Jan-2005  09:43   
You cannot select a file from the route drive. It shows blank for some reason.
But if you drill to a folder - it works perfectly. Seeing how I am saving my word docs to the my documents folder - this works great for me.

I found this also - the switches to control what the user sees:

Const BIF_returnonlyfsdirs = &H0001
Const BIF_dontgobelowdomain = &H0002
Const BIF_statustext = &H0004
Const BIF_returnfsancestors = &H0008
Const BIF_editbox = &H0010
Const BIF_validate = &H0020
Const BIF_nonewfolder = &H0200
Const BIF_browseforcomputer = &H1000
Const BIF_browseforprinter = &H2000
Const BIF_browseincludefiles = &H4000

Const BSF_desktop = 0 'Desktop is the root directory. With BIF_returnonlyfsdirs circumvents problem with OK-button
Const BSF_internetexplorer = 1 'Internet Explorer is the root
Const BSF_programs = 2 'Programs folder of the start menu is the root
Const BSF_controlpanel = 3 'Control Panel is the root. Needs BIF_browseincludefiles
Const BSF_printers = 4 'Printers folder is the root. Needs BIF_browseincludefiles
Const BSF_documents = 5 'Documentsfolder is the root
Const BSF_favorites = 6 'Favorites is the root
Const BSF_startup = 7 'Startup-folder of the startmenu is the root. Needs BIF_browseincludefiles
Const BSF_recent = 8 'Recentfolder is the root. Needs BIF_browseincludefiles
Const BSF_sendto = 9 'Sendto-folder is the root. Needs BIF_browseincludefiles
Const BSF_recyclebin = 10 'Recycle Bin is the root. Needs BIF_browseincludefiles
Const BSF_startmenu = 11 'Start Menu is the root
Const BSF_desktopdirectory = 16 'The Desktopdirectory is the root directory
Const BSF_drives = 17 'The drives (My computer) folder is the root
Const BSF_network = 18 'The networkneighbourhood is the root
Const BSF_nethood = 19 'The nethoodfolder is the root
Const BSF_fonts = 20 'The fontsfolder is the root
Const BSF_templates = 21 'The templatesfolder is the root
Const BSF_commonprograms = 22
Const BSF_commonstartup = 23
Const BSF_commondesktopdir = 24
Const BSF_appdata = 26
Const BSF_printhood = 27
Const BSF_localappdata = 28
Const BSF_altstartup = 29
Const BSF_commonaltstartup = 30
Const BSF_commonfavorites = 31
Const BSF_internetcache = 32
Const BSF_cookies = 33
Const BSF_history = 34
Const BSF_commonappdata = 35
Const BSF_windows = 36
Const BSF_system = 37
Const BSF_programfiles = 38
Const BSF_mypictures = 39
Const BSF_profile = 40
  20-Jan-2005  09:45   
To set it up for the my document folder:

Set objBFF = objSHL.BrowseForFolder(&H0,"Select Folder To Save File",&H4005,5)
  20-Jan-2005  10:32   
"route drive"? I don't understand what you mean by that.

Drilling to a folder works fine. Are you saying that your original code didn't work for you for files, just as it didn't work for me? I'm just trying to sort out whether I need to investigate that further or just consider this a technique for folders only.
  20-Jan-2005  11:22   
It can pick folders or files depending on the switch you selected.
The code does not work for example:
c:\test.txt - file off of your route drive. Will return a blank result.

But it you drill to a folder:
c:\folder\test.txt - it works correctly. Will return c:\folder\test.txt

It seems to have issues with a file located off the route c-drive or d-drive etc.
  20-Jan-2005  11:24   
'Browse for Files and Folders
Set objBFF = objSHL.BrowseForFolder(&H0,"Select Folder To Save File",&H4031,&H0011)

'Browse for Folders Only
'Set objBFF = objSHL.BrowseForFolder(&H0,"Select Folder To Save File",&H0031,&H0011)
  20-Jan-2005  13:23   
It doesn't work for me for any file in any folder.
  20-Jan-2005  13:23   
You mean the root drive, not route, I think.
    Page [ 1 2 3 Next >> ]