PDA

View Full Version : [SOLVED] copy and paste in certain location in word



Lartk
01-14-2013, 02:24 PM
I have some data in an excel document that I copy from excel and paste into word. It is easy to paste this excel data into a new, blank word document with the below code.


Sub Test()
Dim FName As String
Dim FPath As String
Sheets("Sheet1").Range("A3:G80").CopyPicture Appearance:=xlScreen, Format:=xlPicture
With CreateObject("Word.Document")
.Application.Selection.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, DisplayAsIcon:=False
FPath = "C:\Users\kl\Desktop"
FName = Sheets("Sheet1").Range("A6").Text
.SaveAs2 Filename:=FPath & "\" & FName
.Close 0
End With
End Sub

However, I would like to paste into a word document that already has some text and a border (see attached). But it won't work because of the text at the top. That is why I am wondering if I can direct my cursor to be in a position lower than the text up top so the excel data will paste.

Lartk
01-14-2013, 02:41 PM
I tried to add

.Application.TypeParagraph above the Application.Selection line but I get an error.




Sub Test()
Dim FName As String
Dim FPath As String
Sheets("Sheet1").Range("A3:G80").CopyPicture Appearance:=xlScreen, Format:=xlPicture
With CreateObject("Word.Document")
.Application.Selection.TypeParagraph
.Application.Selection.TypeParagraph
.Application.Selection.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, DisplayAsIcon:=False
FPath = "C:\Users\kl\Desktop"
FName = Sheets("Sheet1").Range("A6").Text
.SaveAs2 Filename:=FPath & "\" & FName
.Close 0
End With
End Sub

Lartk
01-15-2013, 09:32 AM
Any ideas?

Kenneth Hobs
01-15-2013, 10:14 AM
Add a bookmark and paste it there.

Option Explicit
'TypeText method
' http://www.excelforum.com/excel-programming/650672-populate-word-document-from-excel.html#post1946784
' http://www.excelforum.com/showthread.php?p=1946784
' http://vbaexpress.com/forum/showthread.php?p=169877
' http://vbaexpress.com/forum/showthread.php?t=24693
' http://www.excelforum.com/excel-programming/791302-excel-to-word-paragraph-and-page-setup.html

'Copy from Excel, paste to Word
'Lucas, http://vbaexpress.com/forum/showthread.php?p=178364

'FormFields
' http://www.mrexcel.com/forum/showthread.php?p=1639696
' http://www.mrexcel.com/forum/showthread.php?t=333200
' http://www.excelforum.com/excel-programming/799070-import-text-fields-from-word.html
' Content Controls
' http://www.vbaexpress.com/forum/showthread.php?t=39654

'Add Hyperlink to Bookmark
' http://www.excelforum.com/excel-programming/664078-use-excel-vba-to-add-a-hyperlink-to-a-word-document.html#post2006430
'Steiner, http://www.vbaexpress.com/kb/getarticle.php?kb_id=126
'Colin_L, http://www.mrexcel.com/forum/showthread.php?t=358054

'Save OLEObject as MSWord Document
' http://vbaexpress.com/forum/showthread.php?t=21619

'Add Table to MSWord
' http://vbaexpress.com/forum/showthread.php?t=23975
' http://vbaexpress.com/forum/showthread.php?p=168731

'Import Word Tables
'vog, http://www.mrexcel.com/forum/showthread.php?t=382541

'Save OLEObject as MSWord DOC
' http://vbaexpress.com/forum/showthread.php?t=21619

'Get Optionbutton info from MSWord DOC
' http://vbaexpress.com/forum/showthread.php?t=22454

'FindReplace Text
' http://www.excelforum.com/excel-programming/682014-replace-word-in-ms-word-with-varable-from-ms-excel.html
' http://www.vbaexpress.com/forum/showthread.php?t=38958
' http://www.vbaexpress.com/forum/showthread.php?p=250215
' http://www.vbaexpress.com/forum/showthread.php?t=42833
' http://support.microsoft.com/kb/240157
' http://word.tips.net/T001833_Generating_a_Count_of_Word_Occurrences.html

' http://www.excelforum.com/excel-programming/794297-struggling-with-a-find-replace-macro-to-word.html

'Bookmarks
' http://vbaexpress.com/forum/showthread.php?p=185718
'Colin_L, http://www.mrexcel.com/forum/showthread.php?t=358054
' http://www.vbaexpress.com/forum/showthread.php?p=253277

'Mail Merge
' http://www.excelforum.com/excel-programming/796614-mail-merge-from-excel.html
' http://www.excelforum.com/excel-programming/798299-print-mail-merge-document.html
'Word 's Catalogue/Directory Mailmerge facility (the terminology depends on the Word version). _
To see how to group records with any mailmerge data source supported by Word, _
check out my Microsoft Word Catalogue/Directory Mailmerge Tutorial at:
' http://lounge.windowssecrets.com/index.php?showtopic=731107
' or
' http://www.gmayor.com/Zips/Catalogue%20Mailmerge.zip