Consulting

Results 1 to 2 of 2

Thread: Convert Text to Table

  1. #1
    VBAX Regular
    Joined
    Sep 2016
    Posts
    16
    Location

    Convert Text to Table

    Hi,

    I have a macro in Word which inserts some text to the end of the document. I would then like to convert the new text into a table and format it. The problem I am having is that it keeps converting the whole document into a table.

    How would I only convert the new text into a table?

    This is what converts the whole document which is no good:

    ActiveDocument.Range.ConvertToTable Separator:=wdSeparatebyTabs

    Thanks!

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,337
    Location
    VBA does what you tell it to. Nothing else. You are telling it to convert the activedocument range (all of it) to a table. You don't show what inserts the text, but look at this:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 2/15/2018
    Dim oRng As Range
      Set oRng = ActiveDocument.Range
      oRng.Collapse wdCollapseEnd
      oRng.InsertBefore vbCr
      oRng.Text = "Some inserted text" & vbTab & "Some more text"
      oRng.ConvertToTable Separator:=wdSeparateByTabs
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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