Results 1 to 3 of 3

Thread: Select File

  1. #1
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have written some code that works with the ActiveWorkbook.

    Dim v1 As Workbook
    Set v1 = ActiveWorkbook

    How can I adjust this to use the File Open dialogue?

    Show file open dialogue
    User selects file
    The selected file becomes v1

    Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can use

    Code:
    Dim v1 As Workbook
    If Application.Dialogs(xlDialogOpen).Show = False Then
      MsgBox "No file selected.", vbExclamation
      Exit Sub
    End If
    Set v1 = ActiveWorkbook
    or

    Code:
    Dim v1 As Workbook
    Dim strFile As String
    With Application.FileDialog(msoFileDialogOpen)
      .Filters.Clear
      .Filters.Add "Excel workbooks", "*.xls"
      If .Show = False Then
    	MsgBox "No file selected.", vbExclamation
    	Exit Sub
      End If
      strFile = .SelectedItems(1)
    End With
    Set v1 = Workbooks.Open(strFile)

  3. #3

Posting Permissions

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