PDA

View Full Version : Method to Update AutoText



WhiteThnder
04-22-2011, 09:53 AM
Hello. I've written a couple routines that, based on AutoText and selected checkboxes, will display in a word document. The problem is, I want to display the total hours for each table (hard coded) within a label that appears through the autotext. Although the label appears after the code is invoked, the programs errors out indicating that the object was not found, and therefore does not update until the subsequent time the button is clicked. Any ideas? Attached is the code and word doc. The code is triggered for the Core Curriculum checkbox. Thanks in advance for your help.

Select Case Core.Value
Case False
Application.ScreenUpdating = False
' Doc.AttachedTemplate.AutoTextEntries.Add "CVI Test", Doc.Sections(2).Range
' Doc.Sections(2).Range.Cut
Application.ScreenRefresh
Application.ScreenUpdating = True
Case True
CheckBox1.Enabled = False
XN.Enabled = False
Application.ScreenUpdating = True
Set rng = Doc.Sections(1).Range
rng.Collapse wdCollapseEnd
Doc.AttachedTemplate.AutoTextEntries("Core").Insert rng, True
Doc.AttachedTemplate.AutoTextEntries("Label").Insert rng, True
Application.ScreenUpdating = True
Application.ScreenRefresh
Sleep 10000
Label1.Caption = days