#1
|
|||
|
|||
Word VBA Tables
Hello,
Im a new student and i am learning vba now, so sorry for my nooby code. I am writig a code that converts a word file into an xml file. at one point i have to analyse a table and add the cells to the xml file. at the beginning ist was enough to use the following code to go to next cell and work with selection: "Selection.MoveRight Unit:=wdCell" with "Selection.MoveRight Unit:=wdCell If selection = "" then (stop analysing this table)" i checked if this was the last cell. now my problem is, if the table has an empty cell in the middle, for example, the code does not analyse the rest of the table. i think it would be helpfull if i can get the information how many cells and rows the table has. I hope you have an other idea and a minute time for me, Thanks |
#2
|
||||
|
||||
Have you searched this forum, in particular, for VBA code relating to table processing?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Quote:
maby i specify the problem: my code goes from heading to heading and depending on what comes after the current heading (Text, another heading or a table), there are different actions. The tables are looking like the picture i added. The bold Cells are the cells where i can find out what to do with ne next cell. but they are flexible. so the Name-Cell could be at the place of the ID-Cell. if there is a table, the Selection (or Range) should be the first cell, than i can put this selection in the right place of the xml file. then the next cell and so on. but i dont know how to stop, so how do i find out if that was the last cell of this table. |
#4
|
||||
|
||||
I wasn't suggesting a general web search, but only of this board's VBA forum. Had you done so, you'd soon find threads like:
https://www.msofficeforums.com/word-...l-another.html https://www.msofficeforums.com/word-...ces-table.html https://www.msofficeforums.com/word-...rd-2010-a.html https://www.msofficeforums.com/word-...ll-tables.html https://www.msofficeforums.com/word-...rm-fields.html These all show how you can process multiple cells, in some cases all cells, in a table without having to first know how many cells there are. Some include logic for processing all tables as well...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Thank you.
I was going through these links. They couldnt really help me with my problem, but got me a step forward. I found a function that gives me the index of the selected table. Then with tables.rows.count and columns.count i thought i could calculate how many cells the selected tables has. but as you can see in the picture above, the first table is flexible and the third row has only two columns. could it be possible that i jump in the table from one bold cell to the next and if the previous bold cell is the same as the current bold cell, this table is done? Hope someone can help me |
#6
|
||||
|
||||
I believe what's in the links (and other threads you could find with a search) are indeed relevant to your problem, but you don't understand it.
Try the following: Code:
Sub Demo() Application.ScreenUpdating = False Dim wdTbl As Table, wdCell As Cell, Rng1 As Range, Rng2 As Range With ActiveDocument For Each wdTbl In .Tables For Each wdCell In wdTbl.Range.Cells Set Rng1 = wdCell.Range Rng1.End = Rng1.End - 1 If Rng1.Font.Bold = True Then Set Rng2 = wdCell.Next.Range Rng2.End = Rng2.End - 1 Select Case Rng1.Text Case "Name": Rng2.InsertBefore "<name>": Rng2.InsertAfter "</name>" Case "ID.": Rng2.InsertBefore "<ID>": Rng2.InsertAfter "</ID>" Case Else End Select End If Next Next End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Thank You macropod
your code really helped me |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help! Baffled by tables in Word | DChord568 | Word Tables | 5 | 11-16-2012 01:36 PM |
Tables in Word | angalis428 | Word | 1 | 01-06-2012 01:12 PM |
Excel Tables to MS Word | ripcurlksm | Word Tables | 2 | 09-09-2011 04:59 AM |
Copying tables to MS Word | 123 | Word Tables | 1 | 03-02-2011 11:25 AM |
Word tables | nbudd | Word Tables | 1 | 05-09-2010 06:31 AM |