VBAProIWish
Well-known Member
- Joined
- Jul 6, 2009
- Messages
- 1,027
- Office Version
- 365
- Platform
- Windows
Hello All,
So I found this awesome code on this site (sorry I forgot the name of the thread) and I'm having trouble with "20S", highlighted at the bottom of the code in red below. I have a Word Template named "Apple" and all my fields populate from Excel into Word correctly, but I'm having trouble with copying a range of more than one cell.
All the other fields work, except for 20S, which is a region of cells that I'm trying to paste into ONE field in Word. I even tried just 2 cells "G01:G02" and that didn't work either.
Is there a way that Excel can tell Word to paste a region of cells (including the formatting would really be great!) and not just one cell?
Thanks
So I found this awesome code on this site (sorry I forgot the name of the thread) and I'm having trouble with "20S", highlighted at the bottom of the code in red below. I have a Word Template named "Apple" and all my fields populate from Excel into Word correctly, but I'm having trouble with copying a range of more than one cell.
All the other fields work, except for 20S, which is a region of cells that I'm trying to paste into ONE field in Word. I even tried just 2 cells "G01:G02" and that didn't work either.
Is there a way that Excel can tell Word to paste a region of cells (including the formatting would really be great!) and not just one cell?
Thanks
Code:
Sub Put_in_Word()
Dim wdApp As Object, wd As Object, ac As Long, ws As Worksheet
Set ws = Worksheets("Sendit")
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
Set wd = wdApp.Documents.Open("C:\Apple, 03.dot")
wdApp.Visible = True
With wd
.formfields("FIELD01").Result = ws.Range("E01").Value
.formfields("FIELD02").Result = ws.Range("E02").Value
.formfields("FIELD03").Result = ws.Range("E03").Value
.formfields("FIELD04").Result = ws.Range("E04").Value
.formfields("FIELD05").Result = ws.Range("E05").Value
.formfields("FIELD06").Result = ws.Range("E06").Value
.formfields("FIELD07").Result = ws.Range("E07").Value
.formfields("FIELD08").Result = ws.Range("E08").Value
.formfields("FIELD09").Result = ws.Range("E09").Value
.formfields("FIELD10").Result = ws.Range("E10").Value
.formfields("FIELD11").Result = ws.Range("E11").Value
.formfields("FIELD12").Result = ws.Range("E12").Value
.formfields("FIELD13").Result = ws.Range("E13").Value
.formfields("FIELD14").Result = ws.Range("E14").Value
.formfields("FIELD15").Result = ws.Range("E15").Value
.formfields("FIELD16").Result = ws.Range("E16").Value
.formfields("FIELD17").Result = ws.Range("E17").Value
.formfields("FIELD18").Result = ws.Range("E18").Value
.formfields("FIELD19").Result = ws.Range("E19").Value
.formfields("FIELD20").Result = ws.Range("E20").Value
[COLOR=red][B] .formfields("FIELD20S").Result = ws.Range("G01:G02").Value[/B][/COLOR]
End With
Set wd = Nothing
Set wdApp = Nothing
End Sub
Last edited: