Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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, I want to use ctrl+down in column A to go to the last entry, copy that cell and paste it into a certain place in an existing word document. I then want to go right 2 cells to column C and copy and paste that cell into another area in word. Finally go to column B and copy/paste that cell in yet another area in word! If possible please post a similar code for what is required that I could play around with a little. Thanks in advance for all those who took the time to read this! Thanks, Kris www.questofages.org *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you have numbered bookmarks in the Word document, you could use a
macro similar to the following: '=========================== 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 '====================================== Kris Taylor wrote: 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, I want to use ctrl+down in column A to go to the last entry, copy that cell and paste it into a certain place in an existing word document. I then want to go right 2 cells to column C and copy and paste that cell into another area in word. Finally go to column B and copy/paste that cell in yet another area in word! If possible please post a similar code for what is required that I could play around with a little. Thanks in advance for all those who took the time to read this! Thanks, Kris www.questofages.org *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I bet this line didn't want the double quotes:
WdApp.Documents.Open Filename:="strFile", _ maybe... WdApp.Documents.Open Filename:=strFile, _ Debra Dalgleish wrote: If you have numbered bookmarks in the Word document, you could use a macro similar to the following: '=========================== 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 '====================================== Kris Taylor wrote: 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, I want to use ctrl+down in column A to go to the last entry, copy that cell and paste it into a certain place in an existing word document. I then want to go right 2 cells to column C and copy and paste that cell into another area in word. Finally go to column B and copy/paste that cell in yet another area in word! If possible please post a similar code for what is required that I could play around with a little. Thanks in advance for all those who took the time to read this! Thanks, Kris www.questofages.org *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks! Yeah, that's what I meant.
(Never change the code at the last minute) Dave Peterson wrote: I bet this line didn't want the double quotes: WdApp.Documents.Open Filename:="strFile", _ maybe... WdApp.Documents.Open Filename:=strFile, _ Debra Dalgleish wrote: If you have numbered bookmarks in the Word document, you could use a macro similar to the following: '=========================== 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 '====================================== Kris Taylor wrote: 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, I want to use ctrl+down in column A to go to the last entry, copy that cell and paste it into a certain place in an existing word document. I then want to go right 2 cells to column C and copy and paste that cell into another area in word. Finally go to column B and copy/paste that cell in yet another area in word! If possible please post a similar code for what is required that I could play around with a little. Thanks in advance for all those who took the time to read this! Thanks, Kris www.questofages.org *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for the replies thus far, however this doesn't seem to work. All
I get is a pop up in excel stating the name of the document that I'm trying to open. Ideas? Kris www.questofages.org *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In the Visual Basic Editor, choose ToolsReferences
Find Microsoft Word x.0 Object Library, and check it Also, check that the bookmarks in the Word document are named bkmk1, bkmk2, etc., or change the code to match your naming. Kris Taylor wrote: Thanks for the replies thus far, however this doesn't seem to work. All I get is a pop up in excel stating the name of the document that I'm trying to open. -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
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) |