ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   time decision for open file in Excel (https://www.excelbanter.com/excel-worksheet-functions/451411-time-decision-open-file-excel.html)

[email protected]

time decision for open file in Excel
 
20 hours before current time is today,open file A
20 hours before current time is yesterday open file B.
How can I use IF THEN function in EXCEL macro

[email protected]

time decision for open file in Excel
 
if 20 hours before current time is today,then open file A
if 20 hours before current time is yesterday,then open file B,
use below formula can work
if (NOW ()-TIME(19,59,59)<TODAY (),"Y","N")

but how to change it as excel macro such that "Y" become "open file A" and "N" become "open file B".

Can I use IF ...THEN...to do this?

thx!


Claus Busch

time decision for open file in Excel
 
Hi Thomas,

Am Mon, 2 May 2016 09:28:03 -0700 (PDT) schrieb :

if 20 hours before current time is today,then open file A
if 20 hours before current time is yesterday,then open file B,
use below formula can work
if (NOW ()-TIME(19,59,59)<TODAY (),"Y","N")


try:

Sub test()
Dim myPath As String

myPath = "C:\Users\myName\Documents\"

If Int(Now() - TimeSerial(20, 0, 0)) = Date Then
Workbooks.Open (myPath & "BookA.xlsx")
Else
Workbooks.Open (myPath & "BookB.xlsx")
End If

End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional

[email protected]

time decision for open file in Excel
 
it works,thx


All times are GMT +1. The time now is 01:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com