Pasting Selected Excel Cells into a Word Doc

D

Dave

Hi.

I need to generate reports in Word, where the content of those reports
is copied from selected parts of an Excel spreadsheet.

Please provide detailed guidance on creating an Excel macro to:
A. Paste selected cells from an Excel XLS into a new Word doc.
B. Run Word VBA code (via the same Excel macro) to reformat those
cells in Word.

More specifically ...

A. I need the Excel macro to:
(1) Copy the currently selected cells onto the Windows clipboard.
(2) Open Word and start a fresh document.
(3) Paste the contents of the clipboard into the new Word doc.

B.
(1) Let me run a Word macro (already recorded) that reformats that
Excel content as a Word table.
(2) Big question here is -- once I've done as per item "A" above --
how do I (can I?) get Excel to recognize code that was recorded as
Word VBA, and run that code in the Excel (macro) environment?

Thanks very much,
Dave
 
G

Gary''s Student

I don't know which clipboard is used here:

Sub place_into_Word()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Selection.Copy
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add

With wrdDoc
wrdApp.Selection.PasteAndFormat (wdPasteDefault)
If Dir("C:\Temp\whatever.doc") <> "" Then
Kill "C:\Temp\whatever.doc"
End If
.SaveAs ("C:\Temp\whatever.doc")
.Close
End With
wrdApp.Quit
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top