![]() |
|
#21
|
||||
|
||||
|
Is the code meant to add a row under the row where the bookmark exists? If not, how do you know there is a cell there and it is empty?
Assuming there is always a cell below the bookmark, I would do the code like this. Read through this carefully because it is considerably different from what you were previously doing and includes some of the testing that is required to deal with the errors that you might encounter Code:
Sub CopyToWord()
Dim myfile As String, wdApp As New Word.Application, wdDoc As Word.Document
Dim i As Integer, dblC22 As Double, wdRng As Word.Range, strAve As String
i = Application.Match("Avg", Sheet1.Range("A1:A20"), 0)
strAve = Range("E" & i).Value
dblC22 = Range("c2")
myfile = Application.GetOpenFilename(, , "Browse for Document")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(myfile)
Select Case dblC22
Case 5, 22, -20
If wdDoc.Bookmarks.Exists("D" & Abs(dblC22)) Then
Set wdRng = wdDoc.Bookmarks.Exists("D" & Abs(dblC22))
If wdRng.Information(wdWithInTable) Then
wdRng.MoveEnd Unit:=wdCell, Count:=4
wdRng.InsertAfter strAve
Else
wdRng.InsertAfter strAve
End If
End If
End Select
End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
| Tags |
| bookmark, if statement, vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Pasting table data so that it will wrap around the table
|
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 |
Table of Bookmarks
|
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 |