View Single Post
 
Old 06-15-2018, 10:47 AM
klutch klutch is offline Windows 7 32bit Office 2016 for Mac
Advanced Beginner
 
Join Date: Jun 2018
Posts: 31
klutch is on a distinguished road
Default Pasting in word table, below bookmarks

Hello, I am very close to completing a macro I've been working on for about two weeks. This is what I've aimed to accomplish:
1. Select a specific cell in excel correlating to specific text in column A (the length of my data rows will vary and I need to copy column E of the last row)
2. Select a word file from libraries (different files for each documentation)
3. Paste into word doc table in relating categories. (Pulling results for 3 different runs)

Here is my code
Code:
 Sub CopyAndPaste()
Dim myfile, wdApp As New Word.Application, wdDoc As Word.Document
myfile = Application.GetOpenFilename(, , "Browse for Document")
Dim i As Integer
i = Application.Match("Avg", Sheet1.Range("A1:A20"), 0)
Range("E" & i).Select
Selection.Copy
 
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(myfile)
'select the word range you want to paste into
  If Range("c2") = 22 Then wdDoc.Bookmarks("d22").Select
  If Range("c2") = 5 Then wdDoc.Bookmarks("d5").Select
  If Range("c2") = -20 Then wdDoc.Bookmarks("d20").Select
 
 
 
    'and paste the clipboard contents
    wdApp.Selection.Paste
End Sub
This code accomplishes my first two objectives, and partially the third.
As you can see, I have used bookmarks to paste where I want to in the doc. However, this table will be updated every 18 months per review standard and the people using it have no VBA experience(they wont know how to change the bookmarks in code). This means that the text being pasted into the current bookmarks will be replaced with the new data. This is no good for what I want to accomplish with this macro.

is there a way to code so that if the bookmark already has text in it, the data will be pasted below it?

I know this is more of an excel problem but I have been told several times that my best luck finding an answer to this question would be in a word forum.

If anyone has anything to add to this I would be very appreciative!!
Reply With Quote