Solved

Add Previous Date to  VBA Code

Posted on 2014-11-03
3
261 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 32

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

786 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