+ Reply to Thread
Results 1 to 3 of 3

get path of latest file in folder with macro

  1. #1
    Registered User
    Join Date
    11-08-2016
    Location
    Constance, Germany
    MS-Off Ver
    Excel 2010
    Posts
    2

    get path of latest file in folder with macro

    hi there,

    Here`s the part of the code I want to change:

    ActiveWorkbook.Worksheets.Add.Name = "Hilfstabelle"

    Range("B1").Select
    ActiveCell.FormulaR1C1 = _
    "=VLOOKUP('C:\Users\famichalsk\Desktop\ExportSAP[export.XLSX]Sheet1'!R[1]C[10],'C:\Users\famichalsk\Desktop\ExportSAP\
    [export.XLSX]Sheet1'!C[10],1,FALSE)"

    Generally the problem is that the part in beetween the brackets [] should change when you have a file in the specific folder, which has a current date. I already tried to check all the files with:

    ...all the variables...

    strPath = "C:\Users\famichalsk\Desktop\ExportSAP"

    ' Use Microsoft Scripting runtime.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(strPath)

    ' Check date on each file in folder.
    For Each objFile In objFolder.Files
    If objFile.DateLastModified > varDate Then
    varDate = objFile.DateLastModified
    strName = objFile.Name
    End If
    Next 'objFile

    ...

    and then paste the variable strName in the [] brackets, but it didn`t work out how I actually imagined...


    I hope you could understand the way I explained it and you can figure out where the problem is and how I can solve it.

    Thanks so far,

    Fabian

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: get path of latest file in folder with macro

    Quote Originally Posted by FaMiChal View Post
    ...
    and then paste the variable strName in the [] brackets, but it didn`t work out how I actually imagined...
    What part didn't work out?

    This will concatenate the strName value within the formula.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    11-08-2016
    Location
    Constance, Germany
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: get path of latest file in folder with macro

    Thank you...this one worked out perfectly...you solved my Problem

+ 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] Macro to get the latest file (excel file) in the folder
    By vigneshwaran in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-06-2022, 05:36 AM
  2. Find latest modified folder and return path to cell
    By dave1983 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2014, 05:27 AM
  3. Replies: 9
    Last Post: 11-28-2013, 05:20 PM
  4. Code to list the folder path and sub folder path of a specific file
    By kalai1587 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2013, 03:51 AM
  5. [SOLVED] Open file by macro from active folder path
    By xbr088 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2013, 10:11 PM
  6. Batch file & macro to copy the latest file from a folder
    By paidlukkha in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-19-2013, 03:05 PM
  7. Macro to open latest file within a folder
    By Roop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2012, 02:56 PM

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