![]() |
|
#6
|
||||
|
||||
|
OK - Here goes,
I'm hoping that I have understood you this time, and that this is what you want - if not, then you will have a little tweaking to do! The following code should do the following when run:
EXCEL:
Code:
Option Explicit
Sub ExportFinalColumnToWord()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Dim MyColumnA As Excel.Range
Dim MyColumnB As Excel.Range
Dim MyColumnC As Excel.Range
Dim MyColumnE As Excel.Range
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
' You need to change the path details here -
' This will create a new document based on your original.
Set myDoc = wdApp.Documents.Add(Template:="C:\Tempo\ExWd.doc")
' Here you need to change the following:
' MySheet - this is the tab name of the sheet in the spreadsheet
' A1,B1,C1,E1 - these are the columns where the data is found
Set MyColumnA = Sheets("MySheet").Range("A1").End(xlDown)
Set MyColumnB = Sheets("MySheet").Range("B1").End(xlDown)
Set MyColumnC = Sheets("MySheet").Range("C1").End(xlDown)
Set MyColumnE = Sheets("MySheet").Range("E1").End(xlDown)
' This is where you get the information pasted into your document.
' Below there are four references to bookmarks - inside the ("").
' You will need to change the names to those of YOUR bookmarks.
' If you want data entered into more than one place, you need to
' create a new line, as below, and change the bookmark name,
' choosing the correct reference at the end 'MyColumnX'
' For example to have the information from Column A in another place,
' you would add the line in green that is below this section.
With myDoc.Bookmarks
.Item("bmMyColumnA").Range.InsertAfter MyColumnA
.Item("bmMyColumnB").Range.InsertAfter MyColumnB
.Item("bmMyColumnC").Range.InsertAfter MyColumnC
.Item("bmMyColumnE").Range.InsertAfter MyColumnE
' .Item("bmMyColumnA_2").Range.InsertAfter MyColumnA
End With
' At this point the Word Application will appear in your taskbar
wdApp.Visible = True
Exit Sub
errorHandler:
wdApp.Quit
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing
End Sub
Hope that does the job! Last edited by Bird_FAT; 05-23-2009 at 07:01 AM. |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shading in Cells in Word Tables | Cindy | Word Tables | 1 | 01-04-2013 02:38 PM |
Opening multiple Excel files within the same Excel window.
|
lost9471 | Excel | 2 | 05-01-2010 01:57 PM |
Word 2007 Password not staying after file transfer.
|
grumalt | Word | 1 | 04-17-2009 12:30 PM |
| Populate cells in Word from a database | hotlilshan | Word | 3 | 12-09-2008 01:51 PM |
| Automatically entering/fill data in cells in Excel 2003 | dipdog | Excel | 0 | 08-17-2006 08:37 AM |