ALL SOFTWARE EXERCISES
- EXERCISES HOME PAGE (840)
- Access 2010 (66)
- Access VBA Macros (17)
- Advanced VBA (29)
- ASP.NET MVC (0)
- ASP.NET webforms - C# (25)
- ASP.NET webforms - VB (27)
- Excel 2010 (83)
- Excel 2013 (10)
- Excel VBA Macros (37)
- Power BI - Excel 2013 (25)
- Power BI - Excel 2016 (23)
- Power BI Desktop (26)
- PowerPivot 2010 (26)
- Report Builder 3.0 (42)
- SQL (156)
- SSAS - multidimensional (21)
- SSAS - tabular (29)
- SSIS Integration Services (18)
- SSRS Reporting Services (53)
- Visual Basic 2010 (42)
- Visual C Sharp 2010 (65)
- WPF - Visual C# (20)
ADVANCED VBA EXERCISES
Exercise: Using an Excel macro to create a Dear Santa letter in Word
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
The answer to the exercise will be included and explained if you attend the Wise Owl course listed below!
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Open the Excel workbook in the above folder - it contains the names of the children for whom you have to buy presents, and what they want:
Someone has thoughtfully created a range name called Children.
Open the Word document in the above folder, and you'll see that it contains a (brief) letter to Santa, containing two bookmarks:
The idea is that your Excel macro will substitute in each child's present request at the first bookmark, and their name at the second one.
The bookmarks have the following names:
|Bookmark||What will be put there|
|Present||The name of the desired present|
|ChildName||The name of the child requesting this|
Close this Word document down, and create a macro in the Excel workbook which loops over the children's names, and for each:
- Opens the Word document.
- Goes to the Present bookmark and writes in the child's present request.
- Goes to the ChildName bookmark and writes in the child's name.
- Saves this document, using the child's name as a file name.
You may find the following macro useful as a hint:
Dim doc As Document
'open up the Word document, getting a reference to it
Set doc = Documents.Open("E:\Referencing applications\Dear Santa.docx")
'go to this document
'write in a present name
doc.Bookmarks("Present").Range.Text = "A really fluffy owl"
'write in the child's name
doc.Bookmarks("ChildName").Range.Text = "Wally Owl"
'save this document, and close it
doc.SaveAs2 "E:\Referencing applications\Wally Owl"
Test that your macro contains one letter for each child, then save it as Suffer the little children.xlsm and close it down, reflecting on another tedious Christmas task now automated!