Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #22  
Old 06-18-2018, 12:18 PM
klutch klutch is offline Pasting in word table, below bookmarks Windows 7 32bit Pasting in word table, below bookmarks Office 2016 for Mac
Advanced Beginner
Pasting in word table, below bookmarks
 
Join Date: Jun 2018
Posts: 31
klutch is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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
I am getting a mismatch error on line
Code:
Set wdRng = wdDoc.Bookmarks.Exists("D" & Abs(dblC22))
Reply With Quote
 

Tags
bookmark, if statement, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pasting in word table, below bookmarks 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
Pasting in word table, below bookmarks 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft