Excel VBA macro. Some cells are automatically filled when a template is used to create a document.

Source: Internet
Author: User

Today, I wrote an Excel macro. When I create an Excel file based on a template, the content of some cells is automatically filled according to the current machine environment.
 

The writing is clumsy, because you are not familiar with VBA and office events, and you are all looking at help. If you can give me some advice, please leave a message.

Private sub workbook_open ()
Dim STR as string
STR = trim (range ("g22"). value)
If STR = "" then
Range ("g22"). value = now
End if
Dim Z as integer
Dim Z2 as integer

If range ("A1"). value = "" then
Z = Day (now) mod 7
Z2 = Day (now) 7
If (z> 0) then
Z2 = Z2 + 1
End if
Range ("A1"). value = "(" & month (now) & ")" & "Week (" & Z2"
End if
End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.