![]() &N prints the total number of pages in the document. &P, &N, &D, &T, &F and &A are certain format codes which can be applied to headers & footers. And we setup each parameter in Page Setup. Now, in the FOR loop, we loop through each worksheet in the workbook which contains the macro. In this case, we have only 1 variable – ws for the worksheet. We start with the usual Dim statement where we declare the variables. Then click on Module and copy this code to the code window on the right. Then on the left hand side, you will see Microsoft Excel Objects. To copy this code to your workbook, press Alt + F11 on your keyboard. LeftFooter = “Path : “ &ActiveWorkbook.Path It will also insert the complete path to the workbook. This sample macro will insert a header/footer in every worksheet in the active workbook. ![]() ![]() If it is just one worksheet you can do it manually, but if it is multiple sheets or all sheets in the workbook which need this information to populated, you can do this using a simple vba macro / code. If you want to insert certain information in the header / footer of the worksheet like the file name / file path or the current date or page number, you can do so using the below code.
0 Comments
Leave a Reply. |