Results 1 to 7 of 7

Thread: How to open a dialog to select files

  1. #1
    macleodjb Guest

    How to open a dialog to select files

    I'm new to VBA and was wondering if someone could help me understand how to write code to open up a listbox that contains a directory path to search out a file to use later in VBA script for retrieval. Basically im having the user select a file and retrieve data from it and have VBA execute commands. Can anyone help this newbie.

  2. #2
    John Coon Guest
    Private Sub TextBox5_Change()
    ' check to see if file exists and then make the insert button enabled

    Dim strMyfile As String

    strMyfile = Dir(TextBox5.Text)


    This should get you started. this will browse to a dir and get the select
    filename and path.
    you just need to change whichever textbox you want. this is set to TextBox5.

    you will need to add a Microsoft command dialog control to your userform.
    that is located under
    the toolbox button. if it is not one of the displayed features then right
    click in listed controls and you should see a note for
    additional controls. look for the command dialog and select checkbox.

    Hope this helps
    John Coon

    Private Sub cmdBrowse_Click()
    On Error GoTo ErrHandler

    ' empty the filename in the dialog box
    CommonDialog1.FileName = ""
    CommonDialog1.MaxFileSize = 32000
    CommonDialog1.Filter = "Drawing Files (*.dwg)|*.dwg"
    CommonDialog1.DefaultExt = "*.dwg"
    CommonDialog1.FilterIndex = 1
    CommonDialog1.DialogTitle = "Select Drawing"
    ' Set Cancel to True.
    CommonDialog1.CancelError = True

    CommonDialog1.ShowOpen
    TextBox5.Text = CommonDialog1.FileName


    Exit Sub
    ErrHandler:
    ' User pressed Cancel button.

    Exit Sub

    End Sub



    "macleodjb" <nospam@address.withheld> wrote in message
    news:14187405.1103766078903.JavaMail.jive@jiveforu m2.autodesk.com...
    I'm new to VBA and was wondering if someone could help me understand how
    to write code to open up a listbox that contains a directory path to
    search out a file to use later in VBA script for retrieval. Basically im
    having the user select a file and retrieve data from it and have VBA
    execute commands. Can anyone help this newbie.

  3. #3
    macleodjb Guest
    Where can i learn about the textbox5 like you suggest. the book i have doesn't really say much about the syntax functionality of it. I have book called VBA for AutoCAD 2004

  4. #4
    Tim Riley Guest
    Search the newsgroups for CommonDialog.cls by Frank Oquendo.

    Tim Riley

    On Thu, 23 Dec 2004 01:40:48 GMT, macleodjb wrote:

    > I'm new to VBA and was wondering if someone could help me understand how to write code to open up a listbox that contains a directory path to search out a file to use later in VBA script for retrieval. Basically im having the user select a file and retrieve data from it and have VBA execute commands. Can anyone help this newbie.

  5. #5
    macleodjb Guest
    I guess i didn't stress how much of a newbie i am....i can't seem to get this to work for me. Im hoping someone can write a small example for me showing it working and then i know i will understand. Its just hard with limited knowledge trying to interpret whats going on and then putting it to work. all i need to do is open a dialog to open an .xls file so i can excute already set up commands in autocad. any help would be greatly appreciated. im working on decreasing my ignorance, but without a teacher its quite difficult

  6. #6
    John Coon Guest
    I posted a zip file in the custer-files for you.
    getfilename-test.zip

    Hope this helps
    John Coon
    "macleodjb" <nospam@address.withheld> wrote in message
    news:5909171.1103910651449.JavaMail.jive@jiveforum 2.autodesk.com...
    I guess i didn't stress how much of a newbie i am....i can't seem to get
    this to work for me. Im hoping someone can write a small example for me
    showing it working and then i know i will understand. Its just hard with
    limited knowledge trying to interpret whats going on and then putting it to
    work. all i need to do is open a dialog to open an .xls file so i can
    excute already set up commands in autocad. any help would be greatly
    appreciated. im working on decreasing my ignorance, but without a teacher
    its quite difficult

  7. #7
    macleodjb Guest
    Thanks alot for all the help. I've got it now

Similar Threads

  1. Select files dialog box
    By dlevy in forum AutoCAD
    Replies: 4
    Last Post: 04-15-2005, 01:56 AM
  2. Windows Open Dialog
    By James Wedding in forum VBA
    Replies: 13
    Last Post: 03-04-2005, 04:26 PM
  3. Selection very slow when properties dialog is open...
    By William Cheng in forum AutoCAD
    Replies: 1
    Last Post: 02-28-2005, 07:45 PM
  4. File open dialog
    By Peter Blazejewicz in forum AutoCAD
    Replies: 2
    Last Post: 01-10-2005, 12:29 PM
  5. Add folders to open dialog
    By T.Willey in forum Customization
    Replies: 8
    Last Post: 12-23-2004, 03:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other forums: Access Forum - Microsoft Office Forum - Exchange Server Forum