VBA 날짜 함수 | Excel VBA 날짜 함수를 사용하는 방법?

Excel VBA DATE 함수

VBA 날짜 는 날짜 및 시간 함수이며 사용중인 시스템 날짜에 따라 현재 날짜 만 반환합니다. 또한 중요한 점은이 함수에 인수가 전혀 없다는 것입니다. 기억해야 할 또 다른 중요한 요소는이 함수입니다. 현재 시스템 날짜를 반환합니다.

Excel에서 우리는 일부 기능 없이는 살 수 없으며 "VBA Date"는 이러한 기능 중 하나입니다. Excel 워크 시트를 자주 사용하는 경우 시스템 날짜에 따라 현재 날짜를 반환하는 "TODAY ()" 라는 함수를 알고 있어야 합니다.

날짜는 매우 간단한 함수이며 사용중인 시스템 날짜에 따라 현재 날짜 만 반환합니다. 이것은 워크 시트 함수“TODAY”와 매우 유사하게 작동하지만 본질적으로 휘발성은 아닙니다.

Excel DATE 함수의 구문은 제공 할 인수가없고 빈 괄호 만 포함하므로 매우 간단합니다.

데이트 ()

괄호는 괄호를 입력 할 필요없이 기능을 사용할 때 기능을 설명하기위한 것입니다.

Excel VBA 날짜 함수를 사용하는 방법?

이 VBA 날짜 Excel 템플릿은 여기에서 다운로드 할 수 있습니다 – VBA 날짜 Excel 템플릿

예 1

A1 셀에 현재 날짜를 삽입하고 다음 단계에 따라 A1 셀에 현재 날짜를 삽입하는 코드를 작성한다고 가정합니다.

1 단계 : 매크로 이름을 만듭니다.

암호:

 하위 날짜 _ 예제 1 ()

2 단계 : A1 셀에 현재 날짜를 저장해야하므로 코드는 Range (“A1”). Value 입니다.

암호:

 Sub Date_Example1 () Range ( "A1"). Value End Sub 

3 단계 : A1 셀에서 현재 날짜가 필요하므로 DATE 함수를 사용하십시오.

암호:

 Sub Date_Example1 () Range ( "A1"). Value = Date End Sub 

4 단계 : 좋습니다. 이제 F5 키를 눌러이 코드를 실행하거나 아래 스크린 샷과 같이 코드를 수동으로 실행할 수도 있습니다. A1 셀에서 현재 날짜를 가져옵니다.

그래서 제가이 코드를 작성할 때 제 시스템에서 현재 날짜는“2019 년 3 월 15 일”입니다.

참고 :  날짜 형식 은 Windows 설정에 따라 다릅니다. 어쨌든 셀 서식에서 날짜 형식을 변경할 수 있습니다.

예제 # 2

귀하가 LIC 에이전트이고 처리 할 고객이 여러 명 있다고 가정합니다. 주요 목표 중 하나는 오늘 지불해야 할 지불금을 확인하여 즉시 전화를 걸어 지불금을받을 수 있도록하는 것입니다.

다음은 데이터베이스에있는 고객 목록입니다.

엑셀 파일을 열 자마자 알려주는 코드를 이미 작성했습니다.

암호:

 Sub Due_Notifier () Dim Duedate As Date Dim i As Long Duedate = Date i = 2 For i = 2 To Cells (Rows.Count, 1) .End (xlUp) .Row If Duedate = DateSerial (Year (Date), Month ( Cells (i, 3) .Value), Day (Cells (i, 3) .Value)) Then MsgBox "고객 이름 :"& Cells (i, 1) .Value & vbNewLine & "프리미엄 금액 :"& Cells (i , 2) .Value End If Next i End Sub 

위 코드를 복사하여 VBA 모듈에 붙여 넣습니다.

이제 "이 통합 문서"옵션을 두 번 클릭합니다.

이제 위의 드롭 다운에서 “Workbook” 을 선택합니다.

"워크 북"옵션을 선택하자마자 개인 매크로가 자동으로 열리는 것을 볼 수 있습니다.

여기에서 매크로 이름은 "Workbook_Open ()"으로 표시되며이 통합 문서가 열릴 때마다 수행해야하는 작업을 의미합니다. 이 통합 문서가 열릴 때마다 우리가 만든 매크로를 실행해야합니다.

따라서 여기에서 우리가 만든 매크로를 이름으로 호출해야합니다. 위 코드에서 매크로 이름은 "Due_Notifier"입니다.

암호:

 Due_Notifier 호출

이제이 통합 문서를 저장하고 닫습니다.

닫은 후 통합 문서를 열고 마법을 확인하십시오.

이제 열겠습니다….

와!!! 현재 날짜에 대한 고객 이름과 만기 금액이 표시됩니다.

Customer Name is “Amar” and the due amount is “20883”. The reason why it is showing this customer name because the due date for Mr Amar is 15th March 2019 i.e. Today.

Now click on Ok, it will show other customer names if the due date is on today.

It is showing Mr Arvind name, his due date is also on 15th March 2019.

Now, you can easily identify the customer names as soon as you come to the office. One of the big headaches is gone.

Similarly, I have created one more excel macro which will send auto birthday emails from your outlook.

Example #3

Assume you are in an “Employee Engagement Team” and you are responsible to send birthday emails to your employees. Identify and sending the email to each and every one separately is a painful job.

Hello, my dear friend doesn’t worry I have created a macro for you to send the auto birthday emails to your employees.

I have created some data to test and below is the image of the same.

You just need to update the employee master according to the headings of the table. Below is the code to send the emails.

Copy the below code and paste in the module.

 Sub Birthday_Wishes() Dim OutlookApp As Outlook.Application Dim OutlookMail As Outlook.MailItem Dim Mydate As Date Dim i As Long Set OutlookApp = New Outlook.Application Mydate = Date i = 2 For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row Set OutlookMail = OutlookApp.CreateItem(olMailItem) If Mydate = DateSerial(Year(Date), Month(Cells(i, 5).Value), Day(Cells(i, 5).Value)) Then OutlookMail.To = Cells(i, 7).Value OutlookMail.CC = Cells(i, 8).Value OutlookMail.BCC = "" OutlookMail.Subject = "Happy Birthday - " & Cells(i, 2).Value OutlookMail.Body = "Dear " & Cells(i, 2).Value & "," & vbNewLine & vbNewLine & _ "We wish you a happy birhday on behalf of the management and we wish all the success in the coming future" & vbNewLine & _ vbNewLine & "Regards," & vbNewLine & "StrIDE Team" OutlookMail.Display OutlookMail.Send End If Next i End Sub 

As soon as you come to the office just open the file and run this code, it will automatically send birthday wishes to the respective email id’s.

Note: You should have Outlook configured in your system.