Solved

Add Previous Date to  VBA Code

Posted on 2014-11-03
3
265 Views
Last Modified: 2014-11-04
Hi Guys,


How do I add the Previous Business day to an Excel File name in a variable string?

eg. In this SelectMatchingWindow File name , I want it to pick up "YY.MM.DD - Daily GMSP Balance Sheet.xlsm"

Sub Macro6()


Filename = SelectMatchingWindow("- Daily GMSP Balance Sheet.xlsm")


  'Sheets("EMEA").Select
   'Windows("10.29.14 - Daily GMSP Balance Sheet.xlsm (sent).xlsx").Activate
    Sheets("EMEA").Select
    Range("A3:M63").Select
0
Comment
Question by:Justincut
3 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 40420399
Use the workday function, e.g.
dim sFileName as string

sFileName=format(application.WorksheetFunction.workDay(now(),-1),"mm.dd.yy") & "- Daily GMSP Balance Sheet.xlsm"
Filename = SelectMatchingWindow(sFileName)

Open in new window

0
 
LVL 12

Expert Comment

by:jkaios
ID: 40420588
Just the intrinsic Format function and the current date:

Filename = SelectMatchingWindow(Format(Date, "yy.mm.dd") &  "- Daily GMSP Balance Sheet.xlsm")
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 40421388
Can I suggest you don't use fullstops within the file name? Some virus checkers will take this file as having multiple file extensions so could include a virus.

Thanks
Rob H
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Getting rid of #VALUE! 7 23
A Table within a User Form 24 44
excel table with over 25000 rows. 3 31
collaboration tool but not sharpoint 2 10
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question