Year / Month / Day ... how to do

0

But I need it to generate a folder for year, month and day Can someone help me? follow ...

' informacoes 
Public cDay, cMonth, cMonthName, cPath

Function identificarData()

' Identificar o caminho na rede

    cPath = "caminho para salvar o arquivo"

' Identificar o dia e mês

    If Day(Date) < 10 Then

        cDay = "0" & Day(Date)

    Else

        cDay = Day(Date)

    End If

    If Month(Date) + 1 < 10 Then

        cMonth = "0" & Month(Date)

    Else

        cMonth = Month(Date)

    End If

' Identificar o nome do mês

    Select Case cMonth

    Case Is = "01"
        cMonthName = "January"

    Case Is = "02"
        cMonthName = "February"

    Case Is = "03"
        cMonthName = "March"

    Case Is = "04"
        cMonthName = "April"

    Case Is = "05"
        cMonthName = "May"

    Case Is = "06"
        cMonthName = "June"

    Case Is = "07"
        cMonthName = "July"

    Case Is = "08"
        cMonthName = "August"

    Case Is = "09"
        cMonthName = "September"

    Case Is = "10"
        cMonthName = "October"

    Case Is = "11"
        cMonthName = "November"

    Case Is = "12"
        cMonthName = "December"

    End Select

End Function
    
asked by anonymous 29.05.2018 / 19:50

1 answer

0

Here is a demo code for how to generate the month and day for a specific year. I suggest running the step-by-step code to understand it (with the F8 key).

Code

Dim Ano As Date, Data As Date
Dim i As Long, DiasNoMes As Long, j As Long
Ano = 2018
j = 0
'Teste Imprimir Meses
For i = 1 To 12
    Debug.Print DateSerial(Ano, i, 1) 'Ou
    'MsgBox DateSerial(Ano, i, 1)
    'Usar Debug.Print ou MsgBox
    Debug.Print Format(DateSerial(Ano, i, 1), "MMMM")

    'Dias no mês
    DiasNoMes = Day(DateSerial(Ano, i + 1, 0))
    Debug.Print DiasNoMes

    'Loop para criar cada dia do mês
    For j = 1 To DiasNoMes
        Debug.Print j
        Debug.Print DateSerial(Ano, i, j)
    Next j
Next i

Explanation

  • Enter 2018 as year: Ano = 2018
  • Loop in 12 months of the year: For i = 1 To 12:Next i
  • The date of the first day of the loop month in the format dd / mm / yyyy: Debug.Print DateSerial(Ano, i + 1, 0)
  • The month written in full: Debug.Print Format(DateSerial(Ano, i, 1), "MMMM")
  • The number of days of the month: DiasNoMes = Day(DateSerial(Ano, i + 1, 0))
  • Loop on each day of the month: For j = 1 To DiasNoMes:Next j
  

Note: To see what is printed with the Debug.Print command, you must enable the Immediate Verification window.

    
30.05.2018 / 13:59