Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Copy And Paste From Excel To Word
Hi All!
I have deciphered the code to open a word document from excel, however I am unaware of how to copy and paste different cells at a time. Here is a general run down of what I wish for the macro to do. First, in excel on the active worksheet titled Tecumseh, I want to use ctrl+down in column A to go to the last entry, copy that cell and paste it into word at a bookmark titled WorkOrder. I then want to go right 2 cells to column C and copy and paste that cell into another bookmark titled ServiceOrder in word. Finally go to column B and copy/paste that cell in yet another bookmark titled Oncor in word! If possible please post a similar code for what is required that I could play around with a little. I received this code from Developpers Dex, however it doesn't seem to work for me. All it does is create a pop up that refers to the word document that I want opened. ======================================= Sub CopyToWord() Dim ws As Worksheet Dim r As Long Dim i As Integer Dim WdApp As Object Dim str As String Dim strFile As String Dim doc As Object Set ws = Sheets("Sheet1") r = ws.Cells(Rows.Count, 1).End(xlUp).Row strFile = "C:\Data\Test.doc" On Error Resume Next Set WdApp = GetObject(, "Word.Application") If Err.Number < 0 Then Err.Clear Set WdApp = CreateObject("Word.Application") End If WdApp.Documents.Open Filename:=strFile, _ ConfirmConversions:=False, ReadOnly:=False Set doc = WdApp.activedocument MsgBox doc.Name WdApp.Visible = True For i = 1 To 3 str = ws.Cells(r, i).Value With WdApp .Selection.GoTo What:=wdGoToBookmark, Name:="bkmk" & i .Selection.TypeText Text:=str End With Next i doc.Close SaveChanges:=wdSaveChanges Set WdApp = Nothing End Sub ========================================== Thanks in advance for all those who took the time to read this! Thanks, Kris www.questofages.org |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Copy and paste into Excel and Word | Excel Discussion (Misc queries) | |||
copy & paste from Excel to Word | Excel Discussion (Misc queries) | |||
Won't let me copy and paste from Excel to Word | Excel Discussion (Misc queries) | |||
COPY & PASTE WORD Doc into EXCEL | Excel Discussion (Misc queries) | |||
copy excel paste to word | Excel Discussion (Misc queries) |