You're invited to a user group meeting!
My next presentation will be for Access Lunchtime (more like dinner time) for those in the UK. All are welcome.
Access Lunchtime (hosted by Maria Barnes) - Deep Dive into Word Automation using VBA and Access
date: Tuesday, May 31
time: 12 noon Central, 18:00 London
this is the link to join -- hope you'll be there!
https://accessusergroups.org/lunch/event/access-lunchtime-4-2022-05-31/
Create professional Word documents from scratch using Word Automation. This is a deep dive into code to write data and text, format, save, and open the finished document with VBA.
We often want to make datasheets look nicer and have many of them in one report. A great way to do this is by creating a Word document with lots of pages and tables.
For each Word table, open a recordset in Access, determine how many rows and columns it has, and create a table in Word that size, with an extra row to be a shaded heading row. Set column widths depending on the table type.
Loop through the recordset and write information to cells, one record and field at a time. Reference any cell in the table by row and column. Format all or any text according to where or what it is.
Learn what objects are handy to dimension and set. While developing, use early-binding and reference the Microsoft Word #.# Object Library. As you write VBA and have advantage of Intellisense, comment and convert constants to values, and write and comment late-binding object declarations to use for deployment.
Write and format text in paragraphs, tables, headers, bookmarks, captions, and hyperlinks. Put tables in cells of tables. Insert and position images.
Create and use paragraph and character styles. Use wildcards in Find/Replace to replace phrases that match a pattern such as being enclosed with parentheses with a particular character style to make many changes at once.
In a sense, we are always working with a range of the document -- whether it's the whole document or just part of it like a table, a cell, a paragraph, some text in the middle of something, .... Learn how to use and set ranges.
For internal links within a document, set bookmarks to reference from somewhere else. Add a hyperlink that goes to a bookmark in the document and set the text to display.
Create lists such as a List of Tables with hyperlinks showing table number, caption, and page number.
Create a Table of Contents with hyperlinks using built-in Heading style references such as Heading 1, Heading 2, and Heading 3.
Define a header that will show at the top of every page. To make the content dynamic, insert text from styles such as Heading 1 and Heading 2, and fields such as date, page number and number of pages.
Use the PageSetup object to set margins. Optionally, set other properties like orientation, gutters, designate odd and even pages, and paper size.
When all is done, save the document, clean up object variables, and open a folder to files or the new document itself.
Get a sample Access database with VBA to create Word documents that enumerate Fonts installed in Windows, Word's built-in Styles, and create documents with information from tables, and insert images from path\files stored in Access.
Here is a very simplified object model for Word: