#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Question VB for Word: Macro to Populate Auto-Text


    Long story short: I need to be able to list data and have that data populate the Auto-Text in MS Word 2003 via VBS. So far I can manipulate the Auto-Text through the following code, but i need to to read 1 line and insert a Hypertext from a second line.

    Code:
    Dim p As Paragraph, r As Range, s As String
    For Each p In ActiveDocument.Paragraphs
         'Skip empty pgphs, like the one that often finishes a doc!
         If Len(p.Range)  2 Then GoTo nextone
         Set r = p.Range
         r.MoveEnd wdCharacter, -1
         s = Left(r.Text, 32)
         ThisDocument.AttachedTemplate.AutoTextEntries.Add Name:=s, Range:=r
    nextone:
    Next p
    MsgBox "Done"
    This one acts line by line. I need One line (first line) to perform as above, I need a second line to be input into a different function. So from above I need to pass this through:

    Code:
    ThisDocument.AttachedTemplate.AutoTextEntries("cName").Value = _ "Input from line 2 goes here"
    cName would pull the data in Line 1 ("s" in previous macro), the input part is Line 2.

    goal:
    ex1 is auto-text with a "value" of <a href="\\UNC\Path\Exhibit1.pdf">Exhibit 1</a>

    I have no idea how to tell it to read line 1 as the first part of the code and then pull the name from 1st part and use it in 2nd part to add the value from the next "paragraph"... any ideas?
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    <edit> wow I was in a foul mood and my comment was very rude and completely uncalled for ... I apologize ...
    Last edited by medialint; June 19th, 2012 at 10:02 AM.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0
    I didn't mean to steal your code and I do apologize for not giving credit I had no idea where it came from to be honest I was what I had stored many ages ago in my scripts folder for word 2003. I actually ended up using wd functions instead... there is still the question of if it possible to "write-in" the HTML link to a relative file-share such as a UNC path... at present the coding I have works with 2-lines to draw in information but requires that the second line be "Pre-linked".

    Any ideas on that?

    here's the script that seemed to work pretty well:
    Code:
    Dim p As Paragraph, s As String
             For Each p In ActiveDocument.Paragraphs
             If Len(p.Range) < 2 Then GoTo next
             Selection.EndKey Unit:=wdLine, Extend:=wdExtend
             s = Selection
             Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdMove
         Selection.EndKey Unit:=wdLine, Extend:=wdExtend
         NormalTemplate.AutoTextEntries.Add Name:=s, Range:=Selection.Range
         Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdMove
    next: 
    Next p 
    MsgBox "Done"  
    End Sub

IMN logo majestic logo threadwatch logo seochat tools logo