ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Export data to from Excel to Word (https://www.excelbanter.com/excel-programming/429877-export-data-excel-word.html)

jswalsh33

Export data to from Excel to Word
 
I have an Excel worksheet with columns of data that was filled in by a Macro.

I would like to extract one column of that data and paste it into a Word
document with a Macro.

I have tried using answers to other questions but they don't quite make it
work.

Help?

Jim

ker_01

Export data to from Excel to Word
 
Jim- I'll provide sample code here (and hopefully it will help); If you can't
get it working, I'd suggest re-posting and indicating what version of Excel
and Word you are using, and where you are getting stuck- is Word not opening?
Is Word open, but your desired contents aren't getting pasted in properly?
etc.

This code should give you a basic starting point; you will still need to use
VBA to cycle through your target column's values to add them to Word instead
of using the WER array.

My apologies to whomever originally posted this code- I didn't capture that
way back (mid 90's?) when I first acquired this snippet.

Best,
Keith

Sub createDoc()

Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Dim wordRng As Word.Range
Dim wordPara As Word.Paragraph
Dim WER(1 To 3) As Variant


Set wordApp = CreateObject("Word.Application")

With wordApp

.WindowState = wdWindowStateMaximize
.Documents.Add
Set wordDoc = wordApp.ActiveDocument
Set wordRng = wordDoc.Range

With wordRng

WER(1) = "tree"
WER(2) = "bed"
WER(3) = "car"

.InsertAfter WER(1)
.InsertParagraphAfter
.InsertAfter WER(2)
.InsertParagraphAfter
.InsertAfter WER(3)
.InsertParagraphAfter

' insert a blank paragraph between the two paragraphs
.InsertParagraphAfter

End With

Set wordPara = wordRng.Paragraphs(3)

With wordPara.Range

.Bold = True
.Italic = False
.Font.Size = 12
.InsertAfter "Report Created: "
.Collapse Direction:=wdCollapseEnd
.InsertDateTime DateTimeFormat:="MM-DD-YY HH:MM:SS"

End With

.ActiveDocument.saveas "c:\Test_Create_Doc.Doc"
.Quit

End With

Set wordPara = Nothing
Set wordRng = Nothing
Set wordDoc = Nothing
Set wordApp = Nothing

End Sub



"jswalsh33" wrote:

I have an Excel worksheet with columns of data that was filled in by a Macro.

I would like to extract one column of that data and paste it into a Word
document with a Macro.

I have tried using answers to other questions but they don't quite make it
work.

Help?

Jim



All times are GMT +1. The time now is 08:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com