Setting defaults through VBA

K

karina thomas

Hi, I am doing something I thought would be quite simple, but it isn't
working. Basically, I am trying to set the default of the left and right
margins in the Normal template through VBA. From what I understand it should
be the following code...

With ActiveDocument.PageSetup
..LeftMargin = InchesToPoints(1)
..RightMargin = InchesToPoints(1)
..SetAsTemplateDefault
End With

While this code does change the margins for the active document, it does not
set them in Normal.dot, so any new documents are still using the old margin
settings. It doesn't generate any errors, it simply doesn't do it.

I tried saving the active document after running the code, because I know
that seems to be the trick when trying to save styles to the attached
template, but that didn't change anything. Any ideas would be appreciated!
 
H

Helmut Weber

Hi Karina,
why not opening normal.dot manually
and setting the margins once and for all?
Otherwise, like this:
Dim oDot As Document
Set oDot = Documents.Open("c:\editx\normal.dot", Visible:=False)
With oDot
.PageSetup.LeftMargin = InchesToPoints(1)
.Save
.Close
End With
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
H

Howard Kaikow

I had suggested that she do the equivalent in another forum, but she does
not want to modify the Normal.dot.
The users run a toolbar button, so she could put the equivalent code in a
macro invoked by the toolbar button.
 
K

karina thomas

In the end Helmut, I ended up doing just that. Thank you for your code
snippet, it was very helpful. Originally I didn't want to open Normal.dot
because I was afraid it would flash on the screen, but I see the
Visible:=False bit on your code and that made it workable for me. I can't
understand why the code I was using before wasn't working...it was actually
from the Microsoft VBA Help files...surprise! surprise! Thanks again for your
help...much appreciated!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top