+ Reply to Thread
Results 1 to 12 of 12

Copy file path to cell

  1. #1
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Question Copy file path to cell

    Good Morning

    If I have a macro that creates a folder baseed on the contents of several cells, what line of code could I use to copy that final file path through to the sheet in cell F2.

    The start location would be for example C:\

    It then looks for a current year folder, a current month folder and then the previous working day folder if any one of those dont appear then it creates it, so i just want the end path that would look something like C:\2014\august\26th

    Thanks Dave

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Copy file path to cell

    range("f2").value = what ever you have saved as
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Copy file path to cell

    thanks for the reply

    Sorry maybe i wasnt clear with what I wanted, that part I would be fine with what I want is the actual file path to be input into cell F2, I will then use the code as you suggested in anther macro to move some files to this created folder location based on the contents of that cell.

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Copy file path to cell

    So you want the path created then?

    I thought you had it

    If I have a macro that creates a folder baseed on the contents of several cells, what line of code could I use to copy that final file path through to the sheet in cell F2.
    Theres a few posts on here about that, i'd use either DIR or, better, the filesystemobject to do this, google both.

  5. #5
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Copy file path to cell

    I have found the following website but just seem to be strugling to get the final result that I require

    http://www.exceltrick.com/formulas_m...object-in-vba/

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Copy file path to cell

    About 1/2 way down the page

    1.'Creating a FileSystemObject
    2.Public FSO As New FileSystemObject
    3.Sub ChkFolder()
    4.Dim Fldr_name As String
    5.Fldr_name = InputBox("Enter the path of the folder to check :")
    6.If Len(Fldr_name) > 0 Then
    7. If FSO.FolderExists(Fldr_name) = True Then
    8. MsgBox "Folder Exists!"
    9. Else
    10. FSO.CreateFolder (Fldr_name)
    11. MsgBox ("Folder Created!")
    12. End If
    13.Else
    14. MsgBox "Wrong Input"
    15.End If
    16.End Sub

  7. #7
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Copy file path to cell

    Does this not require the user to point to the file location though?

    The macro below I use creates a folder and I want the FSO procedure to get the path that has just been created and enter it into the cell without the user having to do this.

    Here is my current macro

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Copy file path to cell

    maybe the step could be added to the existing macro.

    For example at the moment it checks to see if the folder exists, If it does it moves to the next step and carries on the process untill it doesnt find a folder, as soon as no folder is found it then creates on, could there be a line of code that says when evere a folder is created or a folder is found copy filepath just created/found to cell F2 and then Exit Sub

  9. #9
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Copy file path to cell

    If anyone can help, I have tried all sorts off varients of the FSO method and I must be going about it wrong as I am unable to get it to work, I have found lots of different websites with example but none that I can get to do what I need.

  10. #10
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Copy file path to cell

    Bump!!!!!!!

  11. #11
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Copy file path to cell

    Is there a way to find the most recent modified/created folder within a pre determined path and then enter the file path to a cell?

  12. #12
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Copy file path to cell


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] copy of file in the same folder path without opening
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-24-2014, 10:30 AM
  2. [SOLVED] Need Copy file name and contents of that file in a specified path
    By punna111 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-12-2014, 10:37 AM
  3. Replies: 6
    Last Post: 04-22-2013, 08:29 AM
  4. [SOLVED] Get file path from a cell, run a check to see if the file has a specific sheet if yes copy
    By Martha44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-04-2013, 03:35 AM
  5. [SOLVED] Macro to copy file Path with hyperlink.
    By visha_1984 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2013, 08:59 AM

Tags for this Thread

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