Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA code to maintain Template Format called by macro

Status
Not open for further replies.

kdrose

Technical User
Jan 14, 2009
3
US
The following macro was written to append the Template/document 'NMRS Superbill 2009' to the current document. However, tabs, font size, field size and relative positioning of textboxes are not maintained. Sorry, but I do not know about styles. Any additional code that will make this bullet-proof?

[Sub AddBill()
'
' AddBill Macro
'
'
Selection.InsertBreak Type:=wdSectionBreakNextPage
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.25)
.RightMargin = InchesToPoints(0.17)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
Selection.InsertFile FileName:="C:\Documents and Settings\Administrator\Application Data\Microsoft\Templates\NMRS Superbill Final 2009.dot", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
End Sub]

Thanks for any help you can provide.

krose
 
Aaaaaak!

1. why on earth are you appending a .DOT file??????

2. do not use Selection unless you have to...and it is rare that happens.

3. "However, tabs, font size, field size and relative positioning of textboxes are not maintained. "

Why should they? The styles etc. of attached template of the document you are using will apply. You are inserting a file. The fact it is a template (.dot) is irrelevant in this case. You are not attaching the qualities of the template.

4. "Sorry, but I do not know about styles. "

Learn. Word is designed around Styles. You will never use Word fully, and properly, until you grasp styles. The very fact you are having an issue is because of how Word uses styles.

5. "Any additional code that will make this bullet-proof?"

No. Not as it stands.

Perhaps if you explain more fully what it is you are trying to do.

Gerry
 
First of all fumei - I guess I deserve that. However, let me reply to each item:
1. '.dot' is used as others have access to the file/template and I do not want it altered by accident by a well-intentioned individual (has happened before when it was a '.doc' file.
2. In a prior life, this is how I was taught. What, besides Selection, would be better?
3 & 4. I know. That is why I ask the question. I extensively use styles within my documents. I just didn't know how to append a file maintaining the style of the appended document.
5. Just looking for help. If you wish to point me in the direction of further educational materials instead, it would still be appreciated.

All that I am trying to do is to append a billing sheet to the end of an existing document. The billing sheet would then need to be completed before printing.

krose
 
Sorry, I hope you do not feel I was trying to trash you. That is not my intention. I still do not understand what you are doing.

"1. '.dot' is used as others have access to the file/template and I do not want it altered by accident by a well-intentioned individual (has happened before when it was a '.doc' file."

Huh? That does not make any sense to me. You are inserting a .DOT file. What has this got to do with users altering things?

Selection? I never use Selection. Use a range object.

Again, what is it - precisely - that you are trying to do? I have no idea where you are doing the new Section break. At the end of the document? Somewhere in the middle?

But say it was at the end....
Code:
Dim r As Range

Set r = ActiveDocument.Range
With r
   [COLOR=red]' collapse to the end[/color red]
   .Collapse 0
   [COLOR=red]' insert section break[/color red]
   .InsertBreak Type:=wdSectionBreakNextPage
   [COLOR=red]' RESET range object[/color red]
   Set r = ActiveDocument.Range
   [COLOR=red]' collapse again[/color red]
   .Collapse 0
   .InsertFile Filename:=[i]path/filename[/i]
End With
The above could be one way, there are other ways to do this.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top