![]() |
|
#1
|
||||
|
||||
![]() It's not apparent to me how anything in your workbook relates to the table in your document.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
|||
|
|||
![]()
how is it not apparent? Do you mean my code, or my task in general?
From the excel file, I want to take the average mean, which for this instance is located in cell e4, and for each SET POINT, which are -20,5,22, I want to paste it into that column of the word table. So if the set point is -20 I want to paste into the first empty cell of the -20 column, If it is 5 I want to paste into the first empty cell of the 5 column If it is 22 I want to paste into the first empty cell of the 22 column. To differentiate the set points, I have been using if statements, but that has been messy so now I am trying to write three separate macros for each set point. I will be using these macros on the same word table continuously and wish not to change the paste location in the macro every time it is run. I want to find the first empty cell in the specified column, and then select/paste into it or write it in. |
#3
|
|||
|
|||
![]() 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 |
![]() |
Tags |
bookmark, if statement, vba |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
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 |
![]() |
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 |