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 / December 2004

Tip: Looking for answers? Try searching our database.

storing cell content in a string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob - 28 Nov 2004 12:43 GMT
Hi all!

I try to store a cell content (text, tab, tab leader #4) in a text
string for later use.

strCellText = ActiveDocument.Tables(1).Rows(1).Cells(1).Range.Text
discards the tab including the leader.

strCelltext contains text and vbCr 's only.

How does one grab the cell content including tabs and all?

TIA - Rob
Jay Freedman - 28 Nov 2004 19:23 GMT
>Hi all!
>
[quoted text clipped - 9 lines]
>
>TIA - Rob

Hi Rob,

If you use the Asc() function to examine the values of the characters
in strCellText, you should find that there is a 9 that represents the
tab, and a 13 and a 7 that together represent the end-of-cell marker.

However, it isn't possible to capture the leader in a string variable.
For one thing, it isn't a property of the tab (which is a simple
character, vbTab, with the ASCII value 9) -- it's a property of the
*tab stop* in the current paragraph.

If you run this code, you'll see what the setting is for the first
tabstop in the first paragraph in the cell:

   Dim oCell As Cell
   Dim ldr As WdTabLeader
   Set oCell = ActiveDocument.Tables(1).Cell(1, 1)
   ldr = oCell.Range.Paragraphs(1).TabStops(1).Leader
   MsgBox ldr

The numbers shown are 1 less than the ones in the Format > Tabs
dialog, with spaces (None) being 0, dots being 1, dashes being 2, and
underline being 3. (There are also two kinds you can set from a macro
that aren't available in the dialog.)

You would have to store the leader value in a separate variable (and
the same goes for the tabstop's position).

A better idea, if you have control of how the document is initially
created, is to use a specific paragraph style that has the tabstop
position and leader defined in it. Get the name of the style of the
paragraph when you store its text in the string, and reapply that
style when you use the string later.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org
Ed - 29 Nov 2004 16:09 GMT
Please excuse me for jumping in like this . . .
If you get the document and have no control over the initial creation, can
you capture the settings for that paragraph and define a new style to then
apply elsewhere?

Ed

> >Hi all!
> >
[quoted text clipped - 48 lines]
> Jay Freedman
> Microsoft Word MVP         FAQ: http://word.mvps.org
Jay Freedman - 29 Nov 2004 20:36 GMT
Hi Ed,

Yes, you could do something like this:

  Dim oCell As Cell
  Dim oPara As Paragraph
  Dim CellStyle As Style

  Set oCell = ActiveDocument.Tables(1).Cell(1, 1)
  Set oPara = oCell.Range.Paragraphs(1)

  With oPara
     Set CellStyle = ActiveDocument.Styles.Add( _
        Name:=.Style & "+Tab", _
        Type:=wdStyleTypeParagraph)
     CellStyle.BaseStyle = ActiveDocument.Styles(.Style)

     CellStyle.ParagraphFormat.TabStops = .TabStops
  End With

  ActiveDocument.Tables(1).Cell(2, 2).Range _
     .Paragraphs(1).Style = CellStyle

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Please excuse me for jumping in like this . . .
> If you get the document and have no control over the initial
[quoted text clipped - 55 lines]
>> Jay Freedman
>> Microsoft Word MVP         FAQ: http://word.mvps.org
Ed - 30 Nov 2004 14:25 GMT
Thanks, Jay.  I appreciate the boost.

Ed

> Hi Ed,
>
[quoted text clipped - 78 lines]
> >> Jay Freedman
> >> Microsoft Word MVP         FAQ: http://word.mvps.org
Rob - 01 Dec 2004 12:26 GMT
...

> A better idea, if you have control of how the document is initially
> created, is to use a specific paragraph style that has the tabstop
[quoted text clipped - 6 lines]
> Jay Freedman
> Microsoft Word MVP         FAQ: http://word.mvps.org

You're right, this *is* a better idea.

Tanks - Rob

Rate this thread:






 
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.