Results 1 to 6 of 6

VBA open file with variable name with a variable file path.

Threaded View

  1. #1
    Registered User
    Join Date
    02-08-2017
    Location
    Amsterdam
    MS-Off Ver
    microsoft excel 2007
    Posts
    8

    VBA open file with variable name with a variable file path.

    Hi guys,

    I need some help. I'm trying to write a VBA code that opens a CSV file but there are two problems.

    Problem 1:

    The folder in which the CSV file is located changes daily based on today's date, so the file path will look something like this:

    On 07-02-2018: C:/File/20180207/ CSV File
    On 08-02-2018: C:/File/20180208/ CSV File
    On 09-02-2018: C:/File/20180209/ CSV File
    On 10-02-2018: C:/File/20180210/ CSV File

    Etc. The location is basically today's date, YYYYMMDD without any hyphens or slashes.

    Problem 2:

    The filename of CSV file that needs to be opened also changes everyday but it always ends with the same suffix (Done), so for example:

    123Done.CSV
    424Done.CSV
    543Done.CSV
    463Done.CSV
    532Done.CSV

    I've managed to solve the second problem using the following code.

    Dim fname As Variant
    Dim myPath As String

    myPath = "C:\FILE\20180207\"
    fname = Dir(myPath & "*DONE.CSV")

    If fname <> "" Then
    Workbooks.Open (myPath & fname)
    End If

    The only problem is that obviously tomorrow my code won't work as the file needed will be located at C:\FILE\ 20180208\ instead of C:\FILE\ 20180207\.

    Any way to set the filepath to C:\FILE\(Today's date in format YYYYMMDD) ?
    Last edited by BLTnoBacon; 07-02-2018 at 02:23 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to open specified file path with variable date
    By nelsonr15 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2013, 06:57 PM
  2. [SOLVED] I want to set ThisWorkbook.Path inside a variable in order to open a file.
    By grid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2013, 11:07 AM
  3. Replies: 0
    Last Post: 01-27-2013, 12:13 PM
  4. [SOLVED] Macro - Master file to import data from another open file with variable file name
    By jdodz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2012, 10:56 PM
  5. [SOLVED] Open file from a folder and assign that file to an Object variable
    By pratyu in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-22-2012, 02:11 AM
  6. Variable File Path
    By kbruin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2011, 02:26 AM
  7. Place a File Path and File as a Variable
    By SEOT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2008, 11:27 AM

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