View Single Post
 
Old 06-20-2018, 07:32 AM
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

If I wanted to use word table cell selection, how would I implement it? I know Macropod has suggested using bookmarks to select any cell, but from what it seems I will not be able to use bookmarks for this and instead am trying to identify the table cells to paste into. Here is what I have
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 wdoc.tables(7).Cell("B4").Select
    If Range("c2") = 5 Then wdoc.tables(7).Cell("C4").Select
    If Range("c2") = -20 Then wdoc.tables(7).Cell("D4").Select
    
    'and paste the clipboard contents
    wdApp.Selection.Collapse wdCollapseEnd
    wdApp.Selection.Paste
End Sub
With this code I am getting a "object required" error on this line: If Range("c2") = 5 Then wdoc.tables(7).Cell("C4").Select
Reply With Quote