Transfer Excel data to Word

D

Davwe

I have a Excel document with some analysis data, but I want to print
the data in a Word document. Now I succeeded in writing a Excel macro
that copies the data into a new Word document (created from Excel).
However I have two problems.

1. The selection.paste does not work anymore in Office 2000. No
error, but also no selection is pasted in word.

In Excel:

dim worddoc as object
Application.ActivateMicrosoftApp xlMicrosoftWord
Set Worddoc = CreateObject("Word.Application")
Worddoc.Documents.Add


Range(Cells(1, 1), Cells(iEndRow, 5)).Select
Selection.Copy

Application.ActivateMicrosoftApp xlMicrosoftWord

Worddoc.Selection.Paste (no data is pasted)


2. why is excel vba differrent from word vba ? I recorded a macro in
word and tried to use these commants in Excel to make the word
document.


EXCEL :
With Worddoc.ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = xlPortrait [does not recognise xlLandscape]
.TopMargin = 10
.BottomMargin = 10
.LeftMargin = 10
.RightMargin = 10
End With

WORD: (from word macro gives errors in Excel
With ActiveDocument.PageSetup (in word macro)
With worddoc.ActiveDocument.PageSetup (in excel macro)
.LineNumbering.Active = False
.Orientation = wdOrientLandscape (error)
.TopMargin = CentimetersToPoints(2.17) (error)
.BottomMargin = CentimetersToPoints(2.17)
.LeftMargin = CentimetersToPoints(2.54)
.RightMargin = CentimetersToPoints(1.54)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.25)
.FooterDistance = CentimetersToPoints(1.25)
.PageWidth = CentimetersToPoints(29.7)
.PageHeight = CentimetersToPoints(21)
.FirstPageTray = wdPrinterDefaultBin (error)
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.GutterPos = wdGutterPosLeft
End With
 
C

Cleber P. de Souza

test this in the MS Excel:

Dim a As Object
Set a = Nothing
Set a = CreateObject("Word.Application")
a.documents.Add
a.Selection.TypeText ("sample text")
a.Visible = True

Cleber
 

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