Hi Guys!
I'm using the following Excel VBA code to generate a WordDoc and then transfer text from my ExcelDoc to the WordDoc:
It would work perfectly if wasn't by the fact that my WordDoc doesn't keep important formatting like paragraphs and bold text, as you can see in the images below:
-> What I have in my WordDoc:
Please note that in my WordDoc template I have only the start text (it's not merge fields, it's only text itself):
Company: <<Company>>
Address: <<Address>>
Phone: <<Phone number>>
I guess I need a "paste special" code or something like that but I can't find it...
Also, and if possible, I would like to not show in my WordDoc the text "Company: " if there's no Value on cell B2 of my ExcelDoc.
Hopefully someone will be able and kind to help me with this challenge.
If you read this far, thank you very much!
I'm using the following Excel VBA code to generate a WordDoc and then transfer text from my ExcelDoc to the WordDoc:
VBA Code:
Sub Generate_WordDoc()
Dim WordDoc As Object
Dim FileName, TagName, TagValue As String
Dim CustRow As Long
Dim WordContent As Word.Range
With Sheet1
Set wordapp = CreateObject("Word.Application")
wordapp.Visible = True
Set WordDoc = wordapp.Documents.Open(FileName:="C:\File location\Name of file.docx", ReadOnly:=False)
For CustRow = 2 To 4
TagName = .Cells(CustRow, 1).Value
TagValue = .Cells(CustRow, 2).Value
With WordDoc.Content.Find
.Text = TagName
.Replacement.Text = TagValue
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next CustRow
End With
End Sub
It would work perfectly if wasn't by the fact that my WordDoc doesn't keep important formatting like paragraphs and bold text, as you can see in the images below:
Please note that in my WordDoc template I have only the start text (it's not merge fields, it's only text itself):
Company: <<Company>>
Address: <<Address>>
Phone: <<Phone number>>
I guess I need a "paste special" code or something like that but I can't find it...
Also, and if possible, I would like to not show in my WordDoc the text "Company: " if there's no Value on cell B2 of my ExcelDoc.
Hopefully someone will be able and kind to help me with this challenge.
If you read this far, thank you very much!
Last edited by a moderator: