Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Copy/Paste From Excel To Word Macro

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Copy/Paste From Excel To Word Macro

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Copy/Paste From Excel To Word Macro

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Copy/Paste From Excel To Word Macro

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Copy/Paste From Excel To Word Macro

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Copy/Paste From Excel To Word Macro

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy and paste into Excel and Word damonp3 Excel Discussion (Misc queries) 0 March 5th 09 06:55 PM
copy & paste from Excel to Word HeliBarry Excel Discussion (Misc queries) 1 February 29th 08 01:00 PM
Won't let me copy and paste from Excel to Word SueB57 Excel Discussion (Misc queries) 0 November 14th 05 05:14 PM
COPY & PASTE WORD Doc into EXCEL cynjor312 Excel Discussion (Misc queries) 3 November 5th 05 12:28 PM
copy excel paste to word Ciara Excel Discussion (Misc queries) 0 May 20th 05 09:39 AM


All times are GMT +1. The time now is 08:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"