Set the text field text for today / tomorrow / next day / etc. automatically?

I am new to VBA programming, but now I am trying to make a PowerPoint slide that is updated every day. This is a weather forecast slide that is displayed in our lobby, and I am currently manually updating the forecast for seven days every day when I enter. This means that until I come, he will show the current day as yesterday’s date, and the seven-day forecast showing yesterday’s date in the forecast. Ultimately, I would like it to automatically pull in weather data, but as part of this question, I'm just trying to figure out how to display dates in a text box for seven days a week.

Basically, the headline above: (e.g. Wednesday, June 30, 2010)

Then seven days set in columns with: (e.g. June 30 July 1 July 2 July ...)

I would like to set the title to the current date as shown, and then seven text fields below the current day, then tomorrow, then the next day ... and so on until the seventh day.

How do I increase the value of a DateTime? Thank!

+3
source share
4 answers

If you want to go forward in increments of 1 day, you can increase the values ​​of the DateTime variables by adding to them:

Dim d As DateTime
d = Now()

d = d + 1 ''# => tomorrow

This works because inside DateTime it is represented as a floating point integer days before the decimal point and a fraction of the days after the decimal point. (Consequently, adding 0.5 will effectively add 12 hours, although I would not recommend doing this.)

, , DateAdd() (. MSDN).

d = DateAdd("h", 12, d)  ''#=> 12 hours

"" DateAdd().

+5

Excel; VBA . Format DateAdd - , .

Public Sub writeDates()
Dim x As Date, i As Integer
    x = Now
    For i = 1 To 7
       ThisWorkbook.Worksheets(1).Range("A" & i).Value = Format(DateAdd("d", i, x), "dddd, mmmm dd, yyyy")
    Next
End Sub
+3

.

Now(), . , . Date() , - .

VBA.

VBA

+2

, , . addin, , , pps, pps ( ), autoevents, google it email me . ( addit addit imba vba, , ( 2003 ).... 20 , .

I have other bells whistles like reading to / from dates using a string of text tags so that you can greet my blogs on certificate days, etc.

for example, for time updates ... made by automatically changing the slide ActivePresentation.SlideMaster.Shapes (3) .TextFrame.TextRange.Text = Format (now "dddd dd mmmm yyyy") and "." And Format ("hh: mm")

+1
source

Source: https://habr.com/ru/post/1752486/


All Articles