Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    creating tables in Word from Excel (W2K, O2K)

    I am trying to create 3 tables in Word from data taken from Excel. I have managed to create the first table OK and added a couple of paragraphs after it to make a gap. What I cannot see how to do is set the range for the next Tables.Add() command. In effect all I want to do is tell it to go to the end of the document and add the next table.

    Many thanks for any pointers

    Peter

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: creating tables in Word from Excel (W2K, O2K)

    If you record a macro to do that, you get:
    <pre> Selection.EndKey Unit:=wdStory
    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, _
    NumColumns:=3</pre>

    Is that what you need? --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: creating tables in Word from Excel (W2K, O2K)

    I was not using a selection which was why I was having the problem, I think, but your code got me looking in help at <font color=blue>story</font color=blue> . I ended up using:-

    rngStartRange.Expand Unit:=wdStory
    rngStartRange.SetRange Start:=rngStartRange.End, End:=rngStartRange.End

    Not sure this is the right way to do it or not but it works <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Many Thanks, hopefully I can put this to bed now and go back to playing with Access which is much more fun!

    Peter

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: creating tables in Word from Excel (W2K, O2K)

    A slightly more readable version of your second line would be
    <pre>rngStartRange.Collapse Direction:=wdCollapseEnd
    </pre>


    StuartR

  5. #5
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: creating tables in Word from Excel (W2K, O2K)

    Many thanks, much neater <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    That is the trouble trying to code by fumbling through and trying to modify recoded code. Word seems to be much less friendly than Excel when it comes to recording code! The way it disables the mouse as soon as you start recording makes it awkward to do things.

    Does anyone know of a good site for Word VBA? particularly for navigating around documents?

    Peter

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: creating tables in Word from Excel (W2K, O2K)

    I don't know any good books, I learnt Word VBA from the help files and forums like this one.

    I can point you at another useful Range to use in this sort of scenario. ActiveDocument.Content is a predefined range which includes all of the main story, so you could replace your two lines of code with
    <pre>rngStartRange.SetRange Start:=ActiveDocument.Content.End, End:=ActiveDocument.Content.End
    </pre>

    or with
    <pre>set rngStartRange = ActiveDocument.Content.Duplicate
    rngStartRange.Collapse Direction:=wdCollapseEnd
    </pre>

    StuartR

  7. #7
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Maidstone, Kent, England
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: creating tables in Word from Excel (W2K, O2K)

    Thanks, I will have a read up on contents in help. Help in 2000 is not the easist of places to find what you want if you dont know what it is in the first place <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23> Like trying to find a word you can't spell in the dictionary <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    peter

Posting Permissions

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