Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #18  
Old 06-15-2018, 02:15 PM
d4okeefe d4okeefe is offline Pasting in word table, below bookmarks Windows 10 Pasting in word table, below bookmarks Office 2016
Advanced Beginner
 
Join Date: Apr 2013
Posts: 77
d4okeefe is on a distinguished road
Default

There's a lot going on in your original code, so I'll do my best. I can't recreate it perfectly without the original files. Here goes:

Code:
Sub test_ok()
    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
    Dim excel_selection As String
    excel_selection = Selection.Text
     
    wdApp.Visible = True
    Set wdDoc = wdApp.Documents.Open(myfile)
    'select the word range you want to paste into
    
    Dim bk As Bookmark, bk_new As Bookmark
    Dim new_range As Range
    Dim bk_name As String
    If Range("c2") = 22 Then
        Set bk = wdDoc.Bookmarks("d22")
        bk_name = bk.Name
        Set new_range = wdDoc.Range(bk.Start, bk.End)
    End If
    If Range("c2") = 5 Then
        Set bk = wdDoc.Bookmarks("d5")
        bk_name = bk.Name
        Set new_range = wdDoc.Range(bk.Start, bk.End)
    End If
    If Range("c2") = -20 Then
        Set bk = wdDoc.Bookmarks("d20")
        bk_name = bk.Name
        Set new_range = wdDoc.Range(bk.Start, bk.End)
    End If
    
    new_range.InsertAfter (vbCrLf & excel_selection)
    bk.Delete
    Set bk_new = wdDoc.Bookmarks.Add(bk_name, new_range)
End Sub
Reply With Quote
 

Tags
bookmark, if statement, vba

Thread Tools
Display Modes


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:02 AM.


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