Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 10-29-2015, 04:33 PM
gmaxey gmaxey is offline from text to table, with conditions depending on format Windows 7 32bit from text to table, with conditions depending on format Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

If each line is a separate paragraph then select the text to process and:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Dim oTblRng As Word.Range
Dim oTbl As Table
Dim lngIndex As Long
  Set oRng = Selection.Range
  Set oTblRng = ActiveDocument.Range
  oTblRng.Collapse wdCollapseEnd
  Set oTbl = ActiveDocument.Tables.Add(oTblRng, oRng.Paragraphs.Count, 3)
  For lngIndex = 1 To oRng.Paragraphs.Count
    oTbl.Cell(lngIndex, 1).Range.Text = Trim(oRng.Paragraphs(lngIndex).Range.Words(1))
    If oRng.Paragraphs(lngIndex).Range.Words(2).Font.Italic = True Then
      oTbl.Cell(lngIndex, 2).Range.Text = Trim(oRng.Paragraphs(lngIndex).Range.Words(2))
      oTbl.Cell(lngIndex, 3).Range.Text = Trim(oRng.Paragraphs(lngIndex).Range.Words(3))
    Else
      oTbl.Cell(lngIndex, 3).Range.Text = Trim(oRng.Paragraphs(lngIndex).Range.Words(2))
    End If
  Next lngIndex
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
from text to table, with conditions depending on format Format tab leader in “Table of figures” separate from text? WTR_girl12 Word 1 09-03-2015 10:48 AM
from text to table, with conditions depending on format How to Subtract value in table, based on two different conditions nitemath2 Excel 1 06-19-2015 01:28 AM
Hyperlink Format varies, depending on whether Target file was saved or unsaved on Hyperlink Copy RichardDavey Word 0 05-26-2015 05:26 PM
Help - Run-time error 91 - VBA for inserting and formatting text depending on style mtrborges Word VBA 2 02-08-2015 11:35 PM
3x1 Table: text in fields loses paragraph format when being bulleted madasco Word 3 06-07-2013 06:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:09 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft