Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Inserting selected range into Word document

On Tue, 14 Oct 2003 17:31:12 -0400, Debra Dalgleish
wrote:

The following code will insert a line of text, then the selected range
from Excel:

Sub CreateDoc()
Dim WdApp As Object

Selection.Copy
On Error Resume Next
Set WdApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Err.Clear
Set WdApp = CreateObject("Word.Application")
End If

With WdApp
.Visible = True
.Documents.Add DocumentType:=0
.Selection.TypeText "Running Word Using Automation"
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.Paste
End With
Set WdApp = Nothing

End Sub

Ed Stevens wrote:
Using examples previously found here and on MS website, I'm able to
get my macro to start Word , open a new document., and insert some
text into that document. Now I need to be able to insert a range of
selected cells. My first cut was this:

Sub createDoc()

Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Dim wordRng As Word.Range
Dim wordPara As Word.Paragraph

Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True

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

With wordRng

' this works
.InsertAfter "Running Word Using Automation"
' this doesn't
.InsertAfter range(cells(1,1),cells(lngLastRow,lngLastCol))
'nor does this
.InsertAfter
range(cells(1,1),cells(lngLastRow,lngLastCol)).sel ect
<snip rest of code



So, I need someone to get me back on track

Thanks in advance.


That got me where I needed to go. Thanks for the assistance.
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
2007 - link named excel range to word document Karin Excel Discussion (Misc queries) 0 February 8th 10 09:36 PM
Inserting data into Word document by a range of dates from Excel spreadsheet Gordon[_6_] New Users to Excel 3 July 29th 08 08:22 PM
convert excel document to word document (not a picture) frendabrenda1 Excel Discussion (Misc queries) 2 October 6th 06 03:55 PM
Match fonts when inserting an excel worksheet into a word document Penny Excel Worksheet Functions 0 August 23rd 06 04:53 PM
inserting into word document susolive Excel Discussion (Misc queries) 1 February 10th 06 02:50 AM


All times are GMT +1. The time now is 01:16 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"