|
After setting your Word document object, it's good to set the margins for it. This is done by passing the Word document object so PageSetup can be done. VBA procedure that's easy to call in Access as well as Word or any VBA code.
Download zipped BAS file you can import into your VBA projects: bas_Word_SetMargins_s4p.zip
Remember to UNBLOCK files you download to remove the Mark of the Web. Here are steps to do that: https://msaccessgurus.com/MOTW_Unblock.htm
'*************** Code Start ***************************************************** ' module name: mod_Word_SetMargins_s4p '------------------------------------------------------------------------------- ' Purpose : VBA to set margins in a Word document ' uses Document.PageSetup ' Author : crystal (strive4peace) ' Code List: www.msaccessgurus.com/code.htm ' This code: https://msaccessgurus.com/VBA/Word_SetMargins.htm ' LICENSE : ' You may freely use and share this code, but not sell it. ' Keep attribution. Use at your own risk. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' 72 points in an inch '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Word_Margins_Narrow '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Public Sub Word_Margins_Narrow(oDoc As Object) 'make margins 0.5 inches on all sides With oDoc.PageSetup .TopMargin = CInt(0.5 * 72) 'InchesToPoints .BottomMargin = CInt(0.5 * 72) 'InchesToPoints .LeftMargin = CInt(0.6 * 72) 'InchesToPoints .RightMargin = CInt(0.5 * 72) 'InchesToPoints End With End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Word_Margins_1inch '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Public Sub Word_Margins_1inch(oDoc As Object) 'make margins 1 inch on all sides With oDoc.PageSetup .TopMargin = 72 'InchesToPoints .BottomMargin = 72 'InchesToPoints .LeftMargin = 72 'InchesToPoints .RightMargin = 72 'InchesToPoints End With End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Word_Margins '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Public Sub Word_Margins(oDoc As Object _ ,pInchTop As Double _ ,pInchBottom As Double _ ,pInchLeft As Double _ ,pInchRight As Double _ ) 'send what you want for each margin in inches With oDoc.PageSetup .TopMargin = CInt(pInchTop * 72) 'InchesToPoints .BottomMargin = CInt(pInchBottom * 72) 'InchesToPoints .LeftMargin = CInt(pInchLeft * 72) 'InchesToPoints .RightMargin = CInt(pInchRight * 72) 'InchesToPoints End With End Sub '*************** Code End *******************************************************' Made with Color Code add-in posted on http://msaccessgurus.com/tool/Addin_ColorCode.htm ' Code was generated with colors using the free Color Code add-in for Access.
Access is great at managing information, but you can do better formatting with Word!
This code is designed for automation, but you can also call it from Word VBA.
If you like this page, please let me know. Donations mean a lot, thank you
Here's the link for this page in case you want to copy it and share it with someone:
https://msaccessgurus.com/VBA/Word_SetMargins.htm
or in old browsers:
http://www.msaccessgurus.com/VBA/Word_SetMargins.htm
Let's connect and team-develop your application together. I teach you how to do it yourself. My goal is to empower you.
While we build something great together, I'll pull in code and features from my vast libraries as needed, cutting out lots of development time. I'll give you lots of links to good resources.
Do you want your reports to be formatted by Word?
I'd love to help you.
Email me at training@msAccessGurus
~ crystal
the simplest way is best, but usually the hardest to see