Copy Dynamic RANGES of cells from Excel to Bookmarked locations in Word

SanFranExcel

New Member
Joined
Dec 26, 2008
Messages
1
Hi,

I have an worksheet on which I will paste lists of transactions each month. I have a macro that takes those transactions, brings them over to a new worksheet, arranges, sorts, subtotals and adds headers to the transactions (grouped by name). I now want to create a new Word document for each group of transactions. Some of the entries into the Word document will be from single cells in Excel and will be pasted at certain bookmarked locations in a Word template. That part works fine for me. I also, however, would like to copy and paste all of the transactions for a particular group of transactions, along with the header directly over those transactions and the subtotal row, into the word document as well. I cannot figure out how to name the range that will be pasted into Excel.

For the sake of simplicity, below is sample code that I am working with trying to copy a tiny bit of text from a workbook called "test" into a Word template called "Stub" at the bookmark called "History". I want to paste everything cntrl+shift+up and cntrl+shift+right from the active cell.

The problem is with the red text.

Any suggestions would be much appreciated!


Sub Copy_Range_to_Word()

Dim appwd As Object
On Error GoTo notloaded
Set appwd = GetObject(, "Word.Application")
notloaded:
If Err.Number = 429 Then
Set appwd = CreateObject("Word.Application")
End If

appwd.Visible = True

With appwd
.Activate
.Documents.Add Template:=ThisWorkbook.Path & "\stub.dot"
ActiveDocument.Bookmarks("History").Range = Range("A" & ActiveCell.Row, Selection.End(xlUp)).Select & Range(Selection, Selection.End(x1toRight)).Select
End With
' Save the new document
appwd.ActiveDocument.SaveAs Filename:=ThisWorkbook.Path & "\test.doc"
' Close this new word document
appwd.ActiveDocument.Close


End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top