Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Table Help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LEU - 08 Jul 2007 17:10 GMT
I was looking at all the table questions last night and found a macro written
by Lene Fredborg that does almost what I am looking for. What I’m looking for
is how to go to the 5 text location in the cell and copy the rest of the text
(which would very in length) in that cell. The macro below will only get the
second text item.

Dim strWord1 As String
Dim oBkRange As Range
Dim strBk1 As String

'Define bookmark names
strBk1 = "bkTitle"

With ActiveDocument.Sections(1).Range.Tables(2)
 'Trim removes trailing spaces
 strWord1 = Trim(.Cell(1, 4).Range.Words(2).Text)
End With

'Update bookmark text
'Bookmarks must be added again
With ActiveDocument
 Set oBkRange = .Bookmarks(strTitle).Range
 oBkRange.Text = strWord1
 'Add bookmark again
 .Bookmarks.Add Name:=strBk1, Range:=oBkRange
End With
Set oBkRange = Nothing
Lene Fredborg - 08 Jul 2007 18:26 GMT
I am not quite sure what you mean by <how to go to the 5 text location in the
cell and copy the rest of the text>. If you mean that you want to find all
text in the cell except the first 4 characters, you could use the code below
(below, I have named the variable strBkText instead of strWord1).

Note that a table cell ends with a cell marker that has a length of 2.
Therefore, a total of 6 characters are subtracted from the string containing
all text in the cell: the first 4 characters + the cell marker)

With ActiveDocument.Sections(1).Range.Tables(1)
   'First get all text in the cell
   strBkText = .Cell(1, 4).Range.Text
   'Now remove the first 4 characters + the cell marker (length 2)
   strBkText = Mid(strBkText, 5, Len(strBkText) - 6)
End With

Note 1: The code you used as the starting point had to get text from a
footer. This is why ".Section(1)" was included. If your table is simply the
first table in the document, you only need:

With ActiveDocument.Tables(1)

Note 2: In your code, you have this line:
.Bookmarks(strTitle).Range

Your bookmark name, however, is in the variable "strBk1" so the line needs
to be changed to:

.Bookmarks(strBk1).Range

Signature

Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word

> I was looking at all the table questions last night and found a macro written
> by Lene Fredborg that does almost what I am looking for. What I’m looking for
[quoted text clipped - 23 lines]
> End With
> Set oBkRange = Nothing
LEU - 08 Jul 2007 20:22 GMT
Lene,

The macro worked great.
Thank you for your help. I have learned alot about how tables work.

LEU

> I am not quite sure what you mean by <how to go to the 5 text location in the
> cell and copy the rest of the text>. If you mean that you want to find all
[quoted text clipped - 53 lines]
> > End With
> > Set oBkRange = Nothing
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.