#1
|
||||
|
||||
How to insert text at specific location as bold
I searched but cold not find how to do this.
I want to insert the string as bold in the specific location of the word table. for example something like this. Code:
strtxt = "SomeText" Set Rng = Tbl.Cell(i, 3).Range Rng.InsertAfter strtxt (as bold) |
#2
|
||||
|
||||
Try something along the lines of:
Code:
Dim strtxt As String, Tbl As Table, Rng As Range strtxt = "SomeText" Set Tbl = ActiveDocument.Tables(1) Set Rng = Tbl.Cell(i, 3).Range With Rng .End = .End - 1 .Collapse wdCollapseEnd .Text = strtxt .Font.Bold = True End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
Presumably you want to put the text in the cell and format it as bold? In which case
Code:
strtxt = "SomeText" 'set a range to the cell Set rng = tbl.Cell(i, 3).Range 'remove the end of cell character from the range rng.End = rng.End - 1 'Add the text to the range rng.Text = strtxt 'Format the range rng.Font.Bold = True
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#4
|
|||
|
|||
I would suggest recording a macro.
Then do all the modifications and formatting. Finally, look at the code of the macro and see how it did it. The one thing you need to figure out is how you logically want to locate the text you want to bold. Is it a specific line? Is it at the beginning of a known word? Once you have that answered, you can combine it with the code of the macro and automate the task. |
#5
|
||||
|
||||
Thanks for replies. So no direct .insertafter(.bold) will work. I will try and post the result.
|
#6
|
||||
|
||||
Both the macro worked just fine. Thank you very much.
What I wanted is this. Is It right approach? Code:
With Tbl.Cell(i, 3).Range .End = .End - 1 .Collapse wdCollapseEnd .Text = vbCr & "Abstract: " .Font.Bold = True End With With Tbl.Cell(i, 3).Range .End = .End - 1 .Collapse wdCollapseEnd .Text = StrTxt .Font.Bold = False End With |
#7
|
||||
|
||||
I'd suggest:
Code:
Set Rng = Tbl.Cell(i, 3).Range With Rng .End = .End - 1 .Collapse wdCollapseEnd .Text = vbCr & "Abstract: " .Font.Bold = True .Collapse wdCollapseEnd .Text = StrTxt .Font.Bold = False End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
||||
|
||||
This is what I wanted
I tried but as .Collapse wdCollapseEnd was not came in my mind, Every text was getting normal instead of what desired. |
Tags |
wordvba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Text in #1 is made bold, rest of the document is edited, text in #1 is now not bold | footer-assistance | Word | 1 | 06-29-2015 03:49 AM |
Macro to Insert text into the beginning on specific paragraphs unless the paragraph is blank | caboy | Word VBA | 2 | 04-01-2015 07:00 AM |
Macro to insert multiple pictures to word to a specific size and text wrap | mescaL | Word VBA | 3 | 11-03-2014 10:51 PM |
Linking: Insert > Pictures to a specific folder location | hockfam | PowerPoint | 0 | 11-08-2012 08:09 PM |
Create Hyperlinks from Word to specific location in PDF | sukanyae | Word | 0 | 02-25-2010 04:08 PM |