Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2018, 06:08 AM
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

Code:
Sub CopyAndPaste()
    Dim myfile, wdApp As New Word.Application, wDoc 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
    'makes the file appear
    wdApp.Visible = True
    Set wDoc = wdApp.Documents.Open(myfile)
 
    With wDoc
 
    'selects the paste range in the performance review table, depending on the set point
If Range("c2") = 22 Then wDoc.Tables(8).Cell(4, 1).Select
If Range("c2") = 5 Then wDoc.Tables(8).Cell(4, 2).Select
If Range("c2") = -20 Then wDoc.Tables(8).Cell(4, 3).Select
 
 
    'and paste the clipboard contents
    wdApp.Selection.Collapse wdCollapseEnd
    wdApp.Selection.Paste
    wdApp.Selection.Font.Name = "Times New Roman"
    wdApp.Selection.Font.Size = 12
    wdApp.Selection.Font.Bold = wdToggle
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
 
wDoc.Tables(8).Cell(4, 0).Select
wdApp.Selection.TypeText Text:="Performance Review"
wDoc.Tables(8).Rows(4).Select
    wdApp.Selection.Shading.Texture = wdTextureNone
    wdApp.Selection.Shading.ForegroundPatternColor = wdColorAutomatic
    wdApp.Selection.Shading.BackgroundPatternColor = -603914241
   End With
    wDoc.Save
 
 
End Sub
This is what I have right now. It works, but the problem is that if I wish to run it again it just pastes over the previous data. Which is why I need to search for the first blank cell, or have the user select where the macro will paste.
Reply With Quote
Reply

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 11:10 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