+ Reply to Thread
Results 1 to 2 of 2

vba code to open excel file name in previous weekday date

Hybrid View

  1. #1
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    vba code to open excel file name in previous weekday date

    Dear all,

    I have a Question and would really need help to code it.

    i need to open previous week day file always. File name would be like eg, summary22032014.xlsx. say i open this file on 23032014.

    So everyday i would need to open previous day file. via vba code......i use below code.

    HTML Code: 
    The problem is if i execute this code on monday, This code searches for file on previous day date , that is on sunday date.
    I need vba code to be corrected to search for file name dated should be logically Friday.

    if i execute vba code on Tuesday, it should get file name dated on Monday. and it also should meet....if i execute on monday it should logically search file name
    date for Friday. Not a weekend date.

    How could i accomplish this.........please help

  2. #2
    Registered User
    Join Date
    11-13-2006
    Posts
    87

    Re: vba code to open excel file name in previous weekday date

    Sub openbyWorkday()
    Dim wb2 As Workbook, ws As Worksheet
    Dim spath As String, sfilename As String, NamePart As String
    Dim LastWorkDay As Long
    
    spath = "c:\desktop\"
    sfilename = "Summary"
    
    LastWorkDay = 1
    If LCase(Format(Date, "ddd")) = "mon" Then LastWorkDay = 3
    
    NamePart = sfilename & Format(Date - LastWorkDay, "dd.mm.yyyy") & ".xlsx" '"ddmmyyyy"?
    
    Set wb2 = Workbooks.Open(spath & a)
    
    End Sub

+ 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. Replies: 0
    Last Post: 10-02-2013, 01:47 AM
  2. [SOLVED] Code to open another excel file, file name depending on cell contents
    By L-Drr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2013, 11:09 AM
  3. [SOLVED] How to save an excel file to PDF with previous day's date?
    By alexgempesaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2012, 02:34 PM
  4. VBA for excel 2003. Open file dialog box, open 2007 file xlsx, continue with code
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2011, 12:12 AM
  5. [SOLVED] How can I open previous version of saved file in Excel?
    By Cindy W. in forum Excel General
    Replies: 1
    Last Post: 08-01-2005, 06:05 PM

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