![]() |
Exporting excel cell contents to word document
Hello,
How do I export a cells contents to a specific word file as a new line? I also want to be able to label each line with a counter. Say for example my cells value is "cell value" and my word file is "destination.doc" I want to be able to do something like counter = 1 Do until activecell.value = empty {"destination.doc" value = counter & activecell.value} {new line so that next string isnt added to end of prev string in word doc} activecell.offset(1,0).select Loop Any ideas? |
Exporting excel cell contents to word document
Maybe something like this. Assumes word doc already exists. You will
need to add a reference to the Microsoft Word Object Library. Copies data from column A in activesheet. Sub AddData() Dim wordApp As Word.Application Dim wordDoc As Word.Document Dim wordRng As Word.Range Dim cell As Range Dim ColA As Range Dim counter As Long Set ColA = ActiveSheet.Range(Cells(1, 1), _ Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1)) counter = 1 Set wordApp = CreateObject("Word.Application") With wordApp .WindowState = wdWindowStateMaximize .Documents.Open ("c:\Temp\destination.doc") 'change as required Set wordDoc = wordApp.ActiveDocument Set wordRng = wordDoc.Range With wordRng For Each cell In ColA .InsertAfter counter & " " & cell.Value .InsertParagraphAfter counter = counter + 1 Next cell End With .ActiveDocument.Save .Quit End With Set wordRng = Nothing Set wordDoc = Nothing Set wordApp = Nothing End Sub Hope this helps Rowan kaiser wrote: Hello, How do I export a cells contents to a specific word file as a new line? I also want to be able to label each line with a counter. Say for example my cells value is "cell value" and my word file is "destination.doc" I want to be able to do something like counter = 1 Do until activecell.value = empty {"destination.doc" value = counter & activecell.value} {new line so that next string isnt added to end of prev string in word doc} activecell.offset(1,0).select Loop Any ideas? |
Exporting excel cell contents to word document
Thanks Rowan...gives me the base that I need
|
All times are GMT +1. The time now is 11:12 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com