Log in

View Full Version : Running macros from Word template



mpdsal
01-24-2013, 10:27 AM
I am using a Word 2010 template that I created that contains macros for updating several tables within the Word document that the template creates.

The template also uses Bookmarks and Cross-References that get updated. I store the template on a server and added the server address to my Trusted Sites list. The cross references update as they should and the macros run fine as well.

The problem is I have a macro that I run last for one of the tables that removes line spacing, essentially any line with a paragraph mark "^p". Once again the macro is running without errors and it looks fine in the document BUT when I do a print preview it reverts back to having line spaces?? It's driving me nuts! How can I correct this?

One other thing. When I view Developer, Document Template, the template path points to C:\localuser\AppsUser\Roaming\Microsoft\Templates\template.dotm directory when it's stored in a network share??

Why is it doing this?

I appreciate any and all assistance.

Mark

macropod
01-29-2013, 12:49 AM
I have a macro that I run last for one of the tables that removes line spacing, essentially any line with a paragraph mark "^p". Once again the macro is running without errors and it looks fine in the document BUT when I do a print preview it reverts back to having line spaces?? It's driving me nuts! How can I correct this?
Are you saying the deleted paragraph breaks (which is what ^p represents) get restored when you do a print preview? If so, that suggests they're not being deleted at all. Without seeing your code (and a document with an offending table), I doubt there's much we can do to help.

mpdsal
01-29-2013, 07:38 AM
Say no more. Here is the code. Please see word doc attachment. Since I can't upload .docm files the attached is a docx based on the template. I hope this helps to assist with a solution. Thank you.

Public Sub ClearParagraph()
With ActiveDocument.Tables(4).Range.Find
'With ActiveDocument.Tables(3).Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.text = "^p^p"
.Replacement.text = "^p"
.Wrap = wdFindStop
.Forward = True
.Execute Replace:=wdReplaceAll
End With
End Sub

Mark

gmaxey
01-29-2013, 11:04 AM
Mark,

It is happening because the text in table 4 is, for the most part, determined by REF fields. Since your referenences (in table 6 I think) have two paragraphs after Issue # and the issue, it stands to reason that when the REF fields updates (which is does when you print or print preview) that it will revert back whatever the refenced text is.

Perhaps you could split your reference bookmarks inte Issue# and IssueText and then in table four, don't add the extra paragrapn.