Hi,
I'm working with a complex workbook that forms a sales pricelist. This outputs to a worksheet the various components with line item & price.
I want create a macro button that copies these line items and values from Excel into a word template at a certain bookmark.
code so far is below and works fine, but it just copies the formatted excel text into the word doc. I've tried ways to paste onto the Word bookmark eg:
WrdApp.ActiveDocument.Bookmarks("Name").Range.text=Range("Name").text
but it appears to loop and then crash. I want the paste to be "Keep Text Only" option, but can't find a variable for this.
btw: i'm not a regular at VB - however I can get quite a long way by using and adapting existing code.
(this isn't for commercial use, I'm just a salesman who is sick of copy and pasting from excel into word and this will be for me only!)
Code so far:
Private Sub CommandButton4_Click()
Dim wdApp As Object
Dim wd As Object
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:\test\test1.docx")
wdApp.Visible = True
Worksheets("Order form English").Range("A21:P25").Copy
wd.Range.Paste
End Sub
I'm working with a complex workbook that forms a sales pricelist. This outputs to a worksheet the various components with line item & price.
I want create a macro button that copies these line items and values from Excel into a word template at a certain bookmark.
code so far is below and works fine, but it just copies the formatted excel text into the word doc. I've tried ways to paste onto the Word bookmark eg:
WrdApp.ActiveDocument.Bookmarks("Name").Range.text=Range("Name").text
but it appears to loop and then crash. I want the paste to be "Keep Text Only" option, but can't find a variable for this.
btw: i'm not a regular at VB - however I can get quite a long way by using and adapting existing code.
(this isn't for commercial use, I'm just a salesman who is sick of copy and pasting from excel into word and this will be for me only!)
Code so far:
Private Sub CommandButton4_Click()
Dim wdApp As Object
Dim wd As Object
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:\test\test1.docx")
wdApp.Visible = True
Worksheets("Order form English").Range("A21:P25").Copy
wd.Range.Paste
End Sub