Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Autotext - help with Multiple inserts

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jen - 23 Sep 2006 15:32 GMT
Hi

I have VBA routine that automatically inserts and Randomises ATe from
attached template (document) and you insert number for Integer 1 2 50 etc.
And it tosses in some random ATe entries.  Great educationally.

I would also like to be able to select A1 A2 A3 A4 A5 A6 or B1 B2 or even 1
5 15 3 6 2 from attached templated or named Global Template and have the
multientries insert at current cursor position.

Can anyone help me to achieve this?  The randomiser is great for tests.

Would like some help altering randomiser code to insert entries in selected
input order at current cursor position?

Option Explicit

Public Sub InsertRandomAutoText()
   Const cNoOfATRequired As Integer = 2
   Dim rngLocation As Word.Range
   Dim tplAttached As Word.Template
   Dim lngRandMax As Long
   Dim lngIndex As Long
   Dim lngSwapWith As Long
   Dim lngTemp As Long
   Dim alngNumbers() As Long
   ' Highest random number that we need to generate
   Set tplAttached = ActiveDocument.AttachedTemplate
   lngRandMax = tplAttached.AutoTextEntries.Count
   If lngRandMax < cNoOfATRequired Then
       MsgBox "There are insufficient AutoText entries in the" & _
         vbCr & "attached template - at least " & cNoOfATRequired & " are
required"
       Exit Sub
   End If
   ' The starting point is a list of sequential
   ' numbers, one for each AutoText entry
   ReDim alngNumbers(1 To lngRandMax)
   For lngIndex = 1 To lngRandMax
       alngNumbers(lngIndex) = lngIndex
   Next
   ' Seed random number generator
   Randomize
   ' Now randomise the list we've just generated
   For lngIndex = 1 To lngRandMax
       lngSwapWith = Int(lngRandMax * Rnd + 1)
       ' Swap a randomly selected entry with the index entry
       lngTemp = alngNumbers(lngIndex)
       alngNumbers(lngIndex) = alngNumbers(lngSwapWith)
       alngNumbers(lngSwapWith) = lngTemp
   Next
   ' Now insert the first cNoOfATRequired autotext entries
   ' at the end of the document
   Set rngLocation = ActiveDocument.Content
   rngLocation.Collapse wdCollapseEnd
   For lngIndex = 1 To cNoOfATRequired
       ' Insert a random AutoText entry
       Set rngLocation = _
         tplAttached.AutoTextEntries(alngNumbers(lngIndex)).Insert _
         (rngLocation, True)
       rngLocation.Collapse wdCollapseEnd
   Next
End Sub
Jezebel - 24 Sep 2006 01:46 GMT
It would be easier to help if your question were intelligible. Perhaps you
could get an English speaker to help you with the translation and post
again.

> Hi
>
[quoted text clipped - 60 lines]
>    Next
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.