Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-04-2016, 11:31 PM
PRA007's Avatar
PRA007 PRA007 is offline How to insert text at specific location as bold Windows 7 64bit How to insert text at specific location as bold Office 2010 32bit
Competent Performer
How to insert text at specific location as bold
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default 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)
I could not figure out how to do the last line.
Reply With Quote
  #2  
Old 01-05-2016, 01:44 AM
macropod's Avatar
macropod macropod is offline How to insert text at specific location as bold Windows 7 64bit How to insert text at specific location as bold Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

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]
Reply With Quote
  #3  
Old 01-05-2016, 01:47 AM
gmayor's Avatar
gmayor gmayor is offline How to insert text at specific location as bold Windows 10 How to insert text at specific location as bold Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #4  
Old 01-05-2016, 01:56 AM
maxcburger maxcburger is offline How to insert text at specific location as bold Windows XP How to insert text at specific location as bold Office XP
Novice
 
Join Date: Jan 2016
Posts: 5
maxcburger is on a distinguished road
Default

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.
Reply With Quote
  #5  
Old 01-05-2016, 04:43 AM
PRA007's Avatar
PRA007 PRA007 is offline How to insert text at specific location as bold Windows 7 64bit How to insert text at specific location as bold Office 2010 32bit
Competent Performer
How to insert text at specific location as bold
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

Thanks for replies. So no direct .insertafter(.bold) will work. I will try and post the result.
Reply With Quote
  #6  
Old 01-05-2016, 05:23 AM
PRA007's Avatar
PRA007 PRA007 is offline How to insert text at specific location as bold Windows 7 64bit How to insert text at specific location as bold Office 2010 32bit
Competent Performer
How to insert text at specific location as bold
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

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
Reply With Quote
  #7  
Old 01-05-2016, 02:22 PM
macropod's Avatar
macropod macropod is offline How to insert text at specific location as bold Windows 7 64bit How to insert text at specific location as bold Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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'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]
Reply With Quote
  #8  
Old 01-05-2016, 10:12 PM
PRA007's Avatar
PRA007 PRA007 is offline How to insert text at specific location as bold Windows 7 64bit How to insert text at specific location as bold Office 2010 32bit
Competent Performer
How to insert text at specific location as bold
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

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.
Reply With Quote
Reply

Tags
wordvba



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert text at specific location as bold 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
How to insert text at specific location as bold 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
How to insert text at specific location as bold 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:04 PM.


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