Share via

Word VBA Insert Non-Breaking Space in Word Table

Anonymous
2010-10-21T13:21:47+00:00

Hello,

I have table in Word document

US $ **** AUS $ **** CAN $
$2500 $3500 $1500
$850 $450 $350

I need to write the macro in VBA Word i need to insert the non-braking space (Cltr + Shift + Space) only on the table Heads i.e non-breaking space should only come before and after the dollar sign (VBA Macro code should Non-breaking space is inserted before/after $ sign only in the table header)

After the Running the VBA Macro table should like below

US  $ **** AUS  $ **** CAN  $
$2500 $3500 $1500
$850 $450 $350

Please share your comments and ideas

thanks

Orcas


Orcas

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2010-10-21T16:45:57+00:00

    Row.HeadingFormat is the flag that indicates that Word thinks the row is a table heading that repeats on every page. If you have some other definition of a table heading, you'll need to say what it is - perhaps you just want to change the first row of each table, I don't know:

    For Each Table In ActiveDocument.Tables

            Table.Rows(1).Range.Find.Execute FindText:="$", _

                                             Replace:=wdReplaceAll, _

                                             ReplaceWith:=ChrW(160) & "$" & ChrW(160)

        Next


    Enjoy,

    Tony

    www.WordArticles.com

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-10-21T16:06:36+00:00

    Thanks Tony

    The above code works fine but "Row.HeadingFormat" condition always return = 0 since it was unable to insert the non-breaking space before and after $ in table heading

    if block that peace of code, it replace in all the table cells, i need to insert non-breaking space only table heading before and after the $ sign

    please check let me know your comments

    orcas


    Orcas

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-10-21T15:08:50+00:00

    This will replace all $ signs in table heading rows with dollar signs bounded by non-breaking spaces, as asked. I don't quite see why you want one after the dollar sign, and I would have thought you actually want to remove the ordinary space before the dollar sign at the same time, but I daresay you can tweak the code to suit ...

    For Each Table In ActiveDocument.Tables

            For Each Row In Table.Rows

                If Row.HeadingFormat Then

                    Row.Range.Find.Execute FindText:="$", _

                                           Replace:=wdReplaceAll, _

                                           ReplaceWith:=ChrW(160) & "$" & ChrW(160)

                End If

            Next

        Next


    Enjoy,

    Tony

    www.WordArticles.com

    Was this answer helpful?

    0 comments No comments