LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 18
Default macro to copy from excel range to word doc

Thanks to macropod and others, i cobbled together the following code to copy
a specific range from a set of excel files to a specific word document. The
problem i have, is how to insert a paragraph break in word in between each of
the excel ranges after they are pasted into word, otherwise it defeats the
purpose since i would have to cut and paste again to create the necessary
room to add comments in the word doc.

tia for any help.
regards.
george


Sub Francis()

' ==============================
' Define Variables
' ==============================

Dim loanfile As String
Dim collatfile As String

Dim numcollat As Integer
Dim Collatloop As Integer
Dim collatincluded As Integer

Dim wdApp As Word.Application
Dim WdDoc As String

' ==============================
' Initialize Variables
' ==============================

WdDoc = Range("ic_memo_filename").Value + ".doc"
collatincluded = 0
Application.ScreenUpdating = False
numcollat = WorksheetFunction.Max(Range("array_collatfilenum") .Value)

loanfile = ActiveWorkbook.Name

' ==============================
' Loop through each collat file
' ==============================

For Collatloop = 1 To numcollat

If Range("array_collatfileinclude").Cells(Collatloop) = 1 Then

'============================
'Open the collat file
'============================

Workbooks.Open
Filename:=Range("array_collatfilename").Cells(Coll atloop)
collatfile = ActiveWorkbook.Name
collatincluded = collatincluded + 1

'========================================
'Go to Collat File & Copy Data
'========================================

Windows(collatfile).Activate

'Copy the table from the Excel Sheet IC MEMO
Range("ic_memo1").Copy

'Open IC Memo in Word
If Dir(WdDoc) < "" Then
Set wdApp = New Word.Application
wdApp.Visible = False
With wdApp

'open the Word Document

Documents.Open Filename:=WdDoc
With wdApp
Dim BookMarkName As String
BookMarkName = "collat_table"
With ActiveDocument
If .Bookmarks.Exists(BookMarkName) Then
.Bookmarks(BookMarkName).Range.PasteSpecial Link:=True,
DataType:=wdPasteOLEObject, _
Placement:=wdInLine, DisplayAsIcon:=False

Dim oShape As InlineShape
For Each oShape In ActiveDocument.InlineShapes
With oShape
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(16.4)
.Height = CentimetersToPoints(15.5)
End With
Next oShape

.Save
Else
MsgBox "Bookmark: " & BookMarkName & " not found."
End If
End With
End With
End With
Else
MsgBox "File: " & WdDoc & " not found."
End If

' ================================
' go to file and close
' ================================

Range("A1").Copy ' JUST TO CLEAR CLIPBOARD

Windows(collatfile).Activate
ActiveWorkbook.Close savechanges:=False

End If

Next Collatloop

'Release Word object
Set wdApp = Nothing

MsgBox ("IC Memo from " + WorksheetFunction.Text(collatincluded, "0") + "
collateral files created for Francis")

End Sub

 
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
Copy information from Excel to Word using 1 macro mathew Excel Discussion (Misc queries) 0 November 2nd 06 10:01 PM
Copy from WORD to EXCEL using a macro..... Tee Excel Discussion (Misc queries) 1 March 1st 06 06:46 PM
Macro to copy a word doc into an excel doc Tee Excel Discussion (Misc queries) 0 February 22nd 06 12:01 PM
copy from Excel to Word by macro with certain for wmax77 Excel Discussion (Misc queries) 0 February 12th 06 11:33 AM
copy from Excel to word by macro with certain format wmax77 Excel Discussion (Misc queries) 0 February 9th 06 10:07 AM


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