![]() |
#1
|
|||
|
|||
![]()
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 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!! ![]() |
Tags |
bookmark, if statement, vba |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
rebmaboss | Word | 1 | 11-25-2016 02:30 AM |
Pasting text from Excel cell into word without creating a table, and keeping the in-cell formatting | hanvyj | Excel Programming | 0 | 08-28-2015 01:15 AM |
How to insert a table using bookmarks in a document | Catty | Word VBA | 3 | 05-04-2015 03:05 AM |
![]() |
Niy | Word | 3 | 03-28-2012 12:18 AM |
Pasting table in Photoshop cutting off table | azdolfan | Word Tables | 0 | 05-16-2010 01:52 PM |