Formatted text to Word
alpair
Posted messages
1
Status
Member
-
Dartagnan123 -
Dartagnan123 -
Hello everyone,
I am managing a Word document from Excel using VBA. I want to write text with formatting (bold + italic) at the location of a Word bookmark, but I can only write plain text.
I tried using the clipboard, but it crashes.
Here’s my small piece of code:
Dim MyText As String
MyText = "Top the CCM forum"
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Set wordApp = CreateObject("word.application")
Set wordDoc = wordApp.Documents.Open("C:\Test.doc")
'----------- What works ----- :-) ---------
wordDoc.Bookmarks("HERE").Range.Text = MyText
'----------- What doesn't work :-( ------
With wordDoc.Bookmarks("HERE")
.Range.Font.Size = 20
.Range.Bold = wdToggle
.Range.Italic = wdToggle
.Range.Text = MyText
End With
I have been struggling for 2 days surfing the forums which is informative but unfortunately without results.
A little help?
Thank you
I am managing a Word document from Excel using VBA. I want to write text with formatting (bold + italic) at the location of a Word bookmark, but I can only write plain text.
I tried using the clipboard, but it crashes.
Here’s my small piece of code:
Dim MyText As String
MyText = "Top the CCM forum"
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Set wordApp = CreateObject("word.application")
Set wordDoc = wordApp.Documents.Open("C:\Test.doc")
'----------- What works ----- :-) ---------
wordDoc.Bookmarks("HERE").Range.Text = MyText
'----------- What doesn't work :-( ------
With wordDoc.Bookmarks("HERE")
.Range.Font.Size = 20
.Range.Bold = wdToggle
.Range.Italic = wdToggle
.Range.Text = MyText
End With
I have been struggling for 2 days surfing the forums which is informative but unfortunately without results.
A little help?
Thank you
Configuration: Windows XP Internet Explorer 6.0 Office 2003
I am working with VBA Excel 2003 on a Word document.
Do you know how to select text from VBA Excel in a Word document in order to change the Bold format for just a part of a sentence (for example, a word)?
Thank you