how to export a multiline ms excel cell into a word table cell while preserving line breaks through vba code
how to export a multiline ms excel cell into a word table cell while preserving line breaks through vba
Adapt code below to suit your needs
More detailed information is required if you need further help
Place the code below in the Word document module
AND add reference to Microsoft Excel object library (see vba editor \ Tools \ References)Code
Sub InsertTextFromExcelInWordCell() 'excel variables Dim xlWb As Excel.Workbook, xlTxt As String Set xlWb = Excel.Workbooks.Open("C:\TestArea\TextForWord.xlsx") xlTxt = xlWb.Sheets(1).Range("A5").Value 'word variables Dim wdDoc As Word.Document, wdTbl As Word.Table Set wdDoc = ActiveDocument Set wdTbl = wdDoc.Tables(1) 'place value in the cell With wdTbl.Cell(2, 5).Range 'this is row2 & column 5 .Delete .InsertAfter Text:=xlTxt End With xlWb.Close False End Sub
did the code do what you want?
If you have multiline cell content which is separated by Alt + Enter, and now you need to split the multiline contents to separated rows or columns, what can you do? In this article, you will learn how to quickly split multiline cell contents into separated rows or columns.
You haven't added a link to anything
Don’t have an account yet? Register yourself now and be a part of our community!