On button click I want documents to be printed each with a new date for all months in Cell A2.
The code below only updates the date once and the first date is the current date.
When I click on the button, cell A2 needs to be filled with the first date of the month and then this document should be printed.
Once this document is printed cell A2 needs to be updated with the next date and the document again needs to be printed with the updated date.
This continues until the month of December.
Private Sub CommandButton1_Click()
Range("A2").Value = Format(Date, "dd MMMM yy")
ActiveWindow.SelectedSheets.PrintOut copies:=1, collate:=True
Range("A2").Value = Range("A2").Value + 1
ActiveWindow.SelectedSheets.PrintOut copies:=1, collate:=True
End Sub
2条答案
按热度按时间2skhul331#
Please, try the next updated code. It firstly print the sheet with first day of the current month and second time with the last:
Is this what you want/need?
Edited:
Please, test the next version which should do what (I understood) you need:
au9on6nz2#
您可以使用工作表函数EOMONTH来计算上个月的最后一天。然后将日期加1,使其提前到本月的开始。
下面详细介绍了两个选项。
1.按天循环当前月份
1.按天循环到任意日期
选项2已注解掉。若要使用它,请注解掉选项1并取消注解选项2。