Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 216327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:33:15+00:00 2026-05-11T18:33:15+00:00

My Google-Fu is weak today, hopefully this is a simple thing. I need to

  • 0

My Google-Fu is weak today, hopefully this is a simple thing.

I need to set the InitDir property of a VB6 CommonDialog control to start at [My] Computer. If I set InitDir to an empty string, it just defaults to the current directory from the last open dialog.

My code:

With MyCommonDialogControl
    .DialogTitle = "Choose Import File"
    .Filter = "Import Files|*.dbf"
    .InitDir = Environ("HOMEDRIVE") //Needs to be "My Computer"
    .CancelError = False
    .ShowOpen
    If Len(.Filename) = 0 Then Exit Sub
    InputFile = .Filename
End With

Thank you in advance for any assistance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:33:15+00:00Added an answer on May 11, 2026 at 6:33 pm

    I’ve come across a couple of ways to do it – one is through the Environ method which appears to work in both VB6 and VBA – although I’ve never used this method, the other is through p/Invoke referencing: SHGetSpecialFolderLocation and SHGetPathFromIDList in the shell32.dll.

    I didn’t have the code to hand, so I’ve copied and pasted from another site http://en.kioskea.net/faq/sujet-951-vba-vb6-my-documents-environment-variables

    I can’t guarantee the correctness, but it looks very similar to code I’ve used in the past, so it should work with minimal debugging… anyway, at least it points you in the right direction.

    Option Explicit
    Private Type SHITEMID
        cb As Long
        abID As Byte
    End Type
    Private Type ITEMIDLIST
        mkid As SHITEMID
    End Type
    Private Const CSIDL_PERSONAL As Long = &H5
    Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
                            (ByVal hwndOwner As Long, ByVal nFolder As Long, _
                             pidl As ITEMIDLIST) As Long
    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
                            (ByVal pidl As Long, ByVal pszPath As String) As Long
    
    
    Public Function Rep_Documents() As String
        Dim lRet As Long, IDL As ITEMIDLIST, sPath As String
        lRet = SHGetSpecialFolderLocation(100&, CSIDL_PERSONAL, IDL)
        If lRet = 0 Then
            sPath = String$(512, Chr$(0))
            lRet = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath)
            Rep_Documents = Left$(sPath, InStr(sPath, Chr$(0)) - 1)
        Else
            Rep_Documents = vbNullString
        End If
    End Function
    

    Referencing Rep_Documents() will give you a string holding the path name of the My Documents folder. It’s just a case of assigning it to the file dialog’s InitDir property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to define a weak reference Map, whose value is a Set. I
I have a property that looks like this: @property (weak, nonatomic) id<NavigationControllerDelegate> delegate; But
I have searched but apparently my google foo is weak. What I need is
I'm new to serialization, so this might be a simple question, but my google-fu
I've been searching for this for a while, and either my google-fu is weak
Apologies if this is a duplicate and my google-fu weak. I have two options
My Google-fu is apparently weak on this subject, so I'm hoping one of you
My Google-Fu is weak on this one, so mayhaps you all can help. If
My Google-fu is weak and so I turn to the hive mind... I have
i googled for an hour now but maybe my Google-Fu is just too weak,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.