Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2014, 02:26 AM
TSTG TSTG is offline Word VBA Tables Windows 7 64bit Word VBA Tables Office 2007
Novice
Word VBA Tables
 
Join Date: May 2014
Posts: 4
TSTG is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 05-19-2014, 02:40 AM
macropod's Avatar
macropod macropod is offline Word VBA Tables Windows 7 32bit Word VBA Tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Have you searched this forum, in particular, for VBA code relating to table processing?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-20-2014, 12:57 AM
TSTG TSTG is offline Word VBA Tables Windows 7 64bit Word VBA Tables Office 2007
Novice
Word VBA Tables
 
Join Date: May 2014
Posts: 4
TSTG is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Have you searched this forum, in particular, for VBA code relating to table processing?
yes, for my code i was always looking in the vba help or searching the web, and till now i always found an answer. but not for this problem, and thats why i registerd here.

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.
Attached Images
File Type: jpg Table.jpg (63.2 KB, 37 views)
Reply With Quote
  #4  
Old 05-20-2014, 01:12 AM
macropod's Avatar
macropod macropod is offline Word VBA Tables Windows 7 32bit Word VBA Tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 05-23-2014, 12:42 AM
TSTG TSTG is offline Word VBA Tables Windows 7 64bit Word VBA Tables Office 2007
Novice
Word VBA Tables
 
Join Date: May 2014
Posts: 4
TSTG is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 05-23-2014, 02:59 AM
macropod's Avatar
macropod macropod is offline Word VBA Tables Windows 7 32bit Word VBA Tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
Basically, the above code goes through all tables in the document, looking for cells with 'Name' or 'ID.' as their text, then adds tags (not necessarily xml) before & after whatever's in the next cell.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 05-26-2014, 11:45 PM
TSTG TSTG is offline Word VBA Tables Windows 7 64bit Word VBA Tables Office 2007
Novice
Word VBA Tables
 
Join Date: May 2014
Posts: 4
TSTG is on a distinguished road
Default

Thank You macropod
your code really helped me
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word VBA Tables Help! Baffled by tables in Word DChord568 Word Tables 5 11-16-2012 01:36 PM
Word VBA Tables Tables in Word angalis428 Word 1 01-06-2012 01:12 PM
Word VBA Tables 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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:54 AM.


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