Results 1 to 2 of 2

Thread: A Few Word VBA Questions Help!

  1. #1

    Thread Starter
    Addicted Member icemanmt78's Avatar
    Join Date
    May 2000
    Posts
    142

    Angry

    I have a few questions with word VBA.

    1. How do i insert a random field in a word template/document. This field needs to be blank so i can then refer to in in VBA code.

    2. How do i refer to this field in VBA code?

    3. How do i pull a whole sheet or a block of cells from excel into word using vba.

    My aim is to make a template that contains a number of fields. I then want to select a number of cells in excel and place this data into the fields in the word template.

    Any help on any of these q's would be appreciated :-)

    Thanks

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132
    Hi icemanmt78 !!!

    1) If you mean a Word Form field (note: this only belongs
    to word not to forms collection in vba) use the add methode
    of formfields - see also my example

    2) see example

    Code:
    Sub test()
    
    'initial variable
    Dim wfldTest As FormField
    
    'add the formfield and set also an reference to it
    Set wfldTest = FormFields.Add(Selection.Range, wdFieldFormTextInput)
    
    'insert a text to the field
    wfldTest.Result = "myTest"
    
    set wfldTest = Nothing
    
    End Sub

    3) I'm not sure what you want - your aim and this question.
    Why to do need formfields if you want to insert the whole
    excel sheet in Word ?

    But to you question - set an excel referece to the Word VBA procject and you can manipulate excel within word.


    Hope this help

    -cu TheOnly

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width