Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Excel to Word Macro

I have an excel file that has a bunch of different numbers and text
that I would like to go into different tables in a word file. I am
trying to make my creating reports easier, as only certain numbers/
dates/etc. will change. If I could type everything in excel, then run
a macro, that would be great. Is there a way to write a macro to work
with both excel and word? Will the word file need to be formatted in
a certain way? Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Excel to Word Macro

There are so many things you can do. In your excel workbook, you need to add
a sheet named 'Template' and run this code:


In the Visual Basic Editor, set a reference to Word. click Tools
references Microsoft Word 10.0 (for Word 2002; 11.0 for newer versions).
Sub ControlWord()
' You must pick Microsoft Word 8.0 from ToolsReferences
' in the VB editor to execute Word commands.
' See VB Help topic "Controlling One Microsoft Office Application from
Another"
' for more information.
' Originally published by www.MrExcel.com 2/28/1999
Dim appWD As Word.Application
' Create a new instance of Word & make it visible
Set appWD = CreateObject("Word.Application.8")
appWD.Visible = True

Sheets("Data").Select
'Find the last row with data in the database
FinalRow = Range("A9999").End(xlUp).Row
For i = 2 To FinalRow
Sheets("Data").Select
' Copy the name to cell C4
Range("A" & i).Copy Destination:=Sheets("Template").Range("A1:J1")
' Copy data columns, transpose and paste in C10:C13
Range("B" & i & ":J" & i).Copy
Sheets("Template").Select
Range("C10").PasteSpecial Transpose:=True
' Copy the data for the new document to the clipboard
Range("A1:F15").Copy
' Tell Word to create a new document
appWD.Documents.Add
' Tell Word to paste the contents of the clipboard into the new
document
appWD.Selection.Paste
' Save the new document with a sequential file name
appWD.ActiveDocument.SaveAs Filename:="File" & i
' Close this new word document
appWD.ActiveDocument.Close
Next i
' Close the Word application
appWD.Quit
End Sub

You can also try this:
Sub CopyWorksheetsToWord()
' requires a reference to the Word Object library:
' in the VBE select Tools, References and check the Microsoft Word X.X
object library
Dim wdApp As Word.Application, wdDoc As Word.Document, ws As Worksheet
Application.ScreenUpdating = False
Application.StatusBar = "Creating new document..."
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Add
For Each ws In ActiveWorkbook.Worksheets
Application.StatusBar = "Copying data from " & ws.Name & "..."
ws.UsedRange.Copy ' or edit to the range you want to copy
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Ins ertParagraphAfter
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Pas te
Application.CutCopyMode = False
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Ins ertParagraphAfter
' insert page break after all worksheets except the last one
If Not ws.Name = Worksheets(Worksheets.Count).Name Then
With wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range
.InsertParagraphBefore
.Collapse Direction:=wdCollapseEnd
.InsertBreak Type:=wdPageBreak
End With
End If
Next ws
Set ws = Nothing
Application.StatusBar = "Cleaning up..."
' apply normal view
With wdApp.ActiveWindow
If .View.SplitSpecial = wdPaneNone Then
.ActivePane.View.Type = wdNormalView
Else
.View.Type = wdNormalView
End If
End With
Set wdDoc = Nothing
wdApp.Visible = True
Set wdApp = Nothing
Application.StatusBar = False
End Sub



If that doesn't work for you, take a look at this:
http://word.mvps.org/faqs/InterDev/C...WordFromXL.htm

If that doesn't work, look he
http://word.mvps.org/FAQs/InterDev/C...XLFromWord.htm

Regards,
Ryan---


--
RyGuy


" wrote:

I have an excel file that has a bunch of different numbers and text
that I would like to go into different tables in a word file. I am
trying to make my creating reports easier, as only certain numbers/
dates/etc. will change. If I could type everything in excel, then run
a macro, that would be great. Is there a way to write a macro to work
with both excel and word? Will the word file need to be formatted in
a certain way? Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Excel to Word Macro

From personal experience of having ot do the same (with little/no programming
experience) I can also highly recommend Jon Peltier's site:
http://peltiertech.com/Excel/XL_PPT.html

" wrote:

I have an excel file that has a bunch of different numbers and text
that I would like to go into different tables in a word file. I am
trying to make my creating reports easier, as only certain numbers/
dates/etc. will change. If I could type everything in excel, then run
a macro, that would be great. Is there a way to write a macro to work
with both excel and word? Will the word file need to be formatted in
a certain way? Thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converstion of Complex Word VBA macro to Excel Macro Michael[_47_] Excel Programming 1 January 18th 08 12:21 AM
Excel to run Word macro & Word returns value to be written in spreadsheet KS[_2_] Excel Programming 0 November 28th 06 05:33 PM
Need syntax for RUNning a Word macro with an argument, called from an Excel macro Steve[_84_] Excel Programming 3 July 6th 06 07:42 PM
WORD-DELIMITED string vba macro for excel/word jackal2k6 Excel Programming 3 December 23rd 05 04:32 PM
passing arguments from an excel macro to a word macro KWE39 Excel Discussion (Misc queries) 1 July 7th 05 03:56 PM


All times are GMT +1. The time now is 02:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"