Results 1 to 4 of 4

Browse to file and place filename in a cell

Threaded View

dntel123 Browse to file and place... 09-24-2009, 12:17 PM
davegugg Re: Browse to file and place... 09-24-2009, 12:24 PM
dntel123 Re: Browse to file and place... 09-24-2009, 12:39 PM
davegugg Re: Browse to file and place... 09-24-2009, 12:42 PM
  1. #1
    Registered User
    Join Date
    02-17-2008
    Posts
    32

    Browse to file and place filename in a cell

    Hey people,

    I wrote this code a while back to browse to a directory:

    Sub BrowseToDir()
      
      'Declare variables
      Dim strOriginalPath As String
      Dim x As Variant
      Dim strSelectedPath As String
      
      'Remember oroginal path
      strOriginalPath = CurDir
      
      
      'Show dialog and let user browse to a directory
      x = Application.GetSaveAsFilename(InitialFileName:="_", Title:="Browse to desired directory and click Save")
      
      'Get current directory, and show it
      strSelectedPath = CurDir
      Range("C2") = strSelectedPath
      
      'Change back to original drive and path
      On Error Resume Next
      ChDrive strOriginalPath
      ChDir strOriginalPath
      MsgBox strOriginalPath
      On Error GoTo 0
    
    End Sub
    Can anybody help me with instead of inputting the directory into cell 'C2' it puts the actual filename so for example scenario:

    You browse for test.xls in C\:Desktop and this places "C\:Desktop\test.xls" in cell "c2" at the moment i can only display the path

    And also if there is a way that when when u click to open the browse, if you click cancel it leaves the cell intact, at the moment it always puts a directory and overwrites, cant work it out

    Thanks in advance!
    Last edited by dntel123; 09-24-2009 at 12:23 PM. Reason: Extra detail added

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1