Enabling bold

Coolsandyp

New Member
Joined
Mar 29, 2020
Messages
19
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
  2. Mobile
Hello all!
I wish to write a sentence in ms word using vba and in between the sentence,I want to copy paste name from excel. I wish to write the name only in bold. How do I enable bold just before name and copy paste my name and immediately disable bold? Thanks everyone for help.

Also asked here Enabling and diabling bold in ms word
 
Last edited by a moderator:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi Coolsandyp,

Try this. I think it might do what you are looking for.

VBA Code:
Sub PasteName()
    'Declare Variables
    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objRange As Word.Range
    Dim strName As String

    'Open a new Word document
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add

    'Get the name from Excel
    strName = ActiveSheet.Range("A1").Value

    'Insert the sentence
    Set objRange = objDoc.Range
    objRange.InsertAfter "Hi, my name is "
    objRange.InsertAfter strName
    objRange.InsertAfter "!"

    'Make the name bold
    objRange.MoveStart wdCharacter, -Len(strName) - 1
    objRange.Font.Bold = True

End Sub
 
Upvote 0
Hi Coolsandyp,

Try this. I think it might do what you are looking for.

VBA Code:
Sub PasteName()
    'Declare Variables
    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objRange As Word.Range
    Dim strName As String

    'Open a new Word document
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add

    'Get the name from Excel
    strName = ActiveSheet.Range("A1").Value

    'Insert the sentence
    Set objRange = objDoc.Range
    objRange.InsertAfter "Hi, my name is "
    objRange.InsertAfter strName
    objRange.InsertAfter "!"

    'Make the name bold
    objRange.MoveStart wdCharacter, -Len(strName) - 1
    objRange.Font.Bold = True

End Sub
Thanks very much for your kind help. It is not what I wanted but it is still a good lesson for me. Keep it coming. Thanks 😊
 
Upvote 0
Thanks very much for your kind help. It is not what I wanted but it is still a good lesson for me. Keep it coming. Thanks 😊
Hi Coolsandyp,

If you'll write an example sentence showing what you are looking for, I'd be happy to have another go at it for you.
 
Upvote 0

Forum statistics

Threads
1,215,095
Messages
6,123,073
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top