View Single Post
 
Old 06-18-2018, 01:02 PM
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 Applying bookmarks to multiple documents - is it possible?

Hello, I am wondering if it is possible to apply bookmarks to multiple documents (several hundred in this case)? I have a macro that selects a bookmarked cell in a word table and pastes it there. However the document I am pasting into is unique to each performance review. Meaning that technically, each time I run the macro it is pasting into a different document.
Code:
Sub CopyAndPaste()
    Dim myfile, wdApp As New Word.Application, wdDoc As Word.Document
    'select truck report file
   ChDrive "E:\"
ChDir "E:\WG\TVAL\"
myfile = Application.GetOpenFilename(, , "Browse for Document")
    Dim i As Integer
   'searches for row with "avg" then selects column E(avg of temperature mean) of that row.
    i = Application.Match("Avg", Sheet1.Range("A1:A20"), 0)
    'copies the cell
    Range("E" & i).Select
    Selection.Copy
 
    wdApp.Visible = True
    Set wdDoc = wdApp.Documents.Open(myfile)
    'selects the paste range in the performance review table, depending on the set point
    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.Collapse wdCollapseEnd
    wdApp.Selection.Paste
End Sub
My code is dependent on pasting to the bookmarks, as I need to paste into a specific cell within the table.

Does anyone know if applying bookmarks can be done universally? and if not, does anyone have a better solution to pasting into a table cell?
Here are my previous threads working on this problem:
https://www.mrexcel.com/forum/genera...ine-table.html
https://www.ozgrid.com/forum/forum/h...ile-within-vba
But if you could post solutions in this thread that would be great!
Reply With Quote