Solved

Add Previous Date to  VBA Code

Posted on 2014-11-03
3
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

756 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