Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I need to paste a selection from an XL sheet into a Word.rtf document - the
Word document can be a new from opening Word or an already open document My attempts to record the operation has not worked - I need to know how to make make Word active and then go back to XL If this be done with an XL macro please show me Francis Hookham |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Your VBA code may run in only one application. You can "manipulate" the other
through automation. Use the following steps: 1.Import the word type library (tools/references) 2. declare the variable for the word app dim wApp as word.application 3. get reference to a running word app set wApp = getObject(,"Word.Application") 4. use wApp as a word application object to do what you want to do Hint: You may record a new macro in word to see how to paste data. Then copy the vba code to excel and modify it if necessary. "Francis Hookham" wrote: I need to paste a selection from an XL sheet into a Word.rtf document - the Word document can be a new from opening Word or an already open document My attempts to record the operation has not worked - I need to know how to make make Word active and then go back to XL If this be done with an XL macro please show me Francis Hookham |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here are a couple of examples that might help you get started.
Example of pasting to a new Word document: http://groups.google.com/group/micro...cd865d50a7b808 Example of opening and pasting to the Word document: http://groups.google.com/group/micro...c733e1036c0ba0 HTH--Lonnie M. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Many thanks Lonnie and Martin
Ok as far opening the Word doc but I am having no luck with pasting in the copied table 1 In this particular case I want the table pasted in but, in the future, I might want to paste as text so can you help with code for both please 2 Is the reference to 'Microsoft Word Object Library' carried by the macro/worksheet of shall I have to set the reference again in another computer - I shall want to send the resulting worksheet to a friend for whom I am writing this Thanks Francis Hookham Sub PasteAsPic() Dim WrdApp As New Word.Application Dim wrdDoc As New Word.Document 'copy the required data from the Excel File ThisWorkbook.Sheets(1).Range("B2:D10").Copy ' Create a new Word Document Set wrdDoc = WrdApp.Documents.Add(DocumentType:=wdNewBlankDocum ent) WrdApp.Visible = True 'Paste the copied data as Picture WrdApp.Selection.PasteSpecial Placement:=wdInLine, DataType:=wdPasteBitmap 'save the new Word Document wrdDoc.SaveAs "c:\Filename.doc", wdWord 'clean up code wrdDoc.Close Set wrdDoc = Nothing Set WrdApp = Nothing End Sub "Lonnie M." wrote in message ups.com... Here are a couple of examples that might help you get started. Example of pasting to a new Word document: http://groups.google.com/group/micro...cd865d50a7b808 Example of opening and pasting to the Word document: http://groups.google.com/group/micro...c733e1036c0ba0 HTH--Lonnie M. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
1. To paste as plain text use Selection.PasteAndFormat (wdFormatPlainText)
and to paste as table use Selection.PasteAndFormat (wdPasteDefault) 2. Yes, the type library reference is kept with the excel workbook "Francis Hookham" написа: Many thanks Lonnie and Martin Ok as far opening the Word doc but I am having no luck with pasting in the copied table 1 In this particular case I want the table pasted in but, in the future, I might want to paste as text so can you help with code for both please 2 Is the reference to 'Microsoft Word Object Library' carried by the macro/worksheet of shall I have to set the reference again in another computer - I shall want to send the resulting worksheet to a friend for whom I am writing this Thanks Francis Hookham Sub PasteAsPic() Dim WrdApp As New Word.Application Dim wrdDoc As New Word.Document 'copy the required data from the Excel File ThisWorkbook.Sheets(1).Range("B2:D10").Copy ' Create a new Word Document Set wrdDoc = WrdApp.Documents.Add(DocumentType:=wdNewBlankDocum ent) WrdApp.Visible = True 'Paste the copied data as Picture WrdApp.Selection.PasteSpecial Placement:=wdInLine, DataType:=wdPasteBitmap 'save the new Word Document wrdDoc.SaveAs "c:\Filename.doc", wdWord 'clean up code wrdDoc.Close Set wrdDoc = Nothing Set WrdApp = Nothing End Sub "Lonnie M." wrote in message ups.com... Here are a couple of examples that might help you get started. Example of pasting to a new Word document: http://groups.google.com/group/micro...cd865d50a7b808 Example of opening and pasting to the Word document: http://groups.google.com/group/micro...c733e1036c0ba0 HTH--Lonnie M. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Martin - thank you for your quick response but something is wrong in the
following macro which stops at 'Selection.PasteAndFormat (wdPasteDefault)' It also stops with 'Selection.PasteAndFormat (wdFormatPlainText)' Please help! When it is does run properly I should like to change to using an existing Word document(Calendar.rtf) which already exists in the same folder as the XL sheet. Please also help with the code for that This is the macro which will not run Sub DataFromXLToWord() Dim WrdApp As New Word.Application Dim wrdDoc As New Word.Document 'copy the required data from the Excel File ThisWorkbook.Sheets(1).Range("B2:D10").Copy ' Create a new Word Document Set wrdDoc = WrdApp.Documents.Add(DocumentType:=wdNewBlankDocum ent) WrdApp.Visible = True 'Paste the copied data as table Selection.PasteAndFormat (wdPasteDefault) 'Selection.PasteAndFormat (wdFormatPlainText) 'save the new Word Document wrdDoc.SaveAs "c:\Filename.doc", wdWord 'clean up code wrdDoc.Close Set wrdDoc = Nothing Set WrdApp = Nothing End Sub Francis Hookham ____________________________________________ "Martin Krastev" wrote in message ... 1. To paste as plain text use Selection.PasteAndFormat (wdFormatPlainText) and to paste as table use Selection.PasteAndFormat (wdPasteDefault) 2. Yes, the type library reference is kept with the excel workbook "Francis Hookham" ??????: Many thanks Lonnie and Martin Ok as far opening the Word doc but I am having no luck with pasting in the copied table 1 In this particular case I want the table pasted in but, in the future, I might want to paste as text so can you help with code for both please 2 Is the reference to 'Microsoft Word Object Library' carried by the macro/worksheet of shall I have to set the reference again in another computer - I shall want to send the resulting worksheet to a friend for whom I am writing this Thanks Francis Hookham Sub PasteAsPic() Dim WrdApp As New Word.Application Dim wrdDoc As New Word.Document 'copy the required data from the Excel File ThisWorkbook.Sheets(1).Range("B2:D10").Copy ' Create a new Word Document Set wrdDoc = WrdApp.Documents.Add(DocumentType:=wdNewBlankDocum ent) WrdApp.Visible = True 'Paste the copied data as Picture WrdApp.Selection.PasteSpecial Placement:=wdInLine, DataType:=wdPasteBitmap 'save the new Word Document wrdDoc.SaveAs "c:\Filename.doc", wdWord 'clean up code wrdDoc.Close Set wrdDoc = Nothing Set WrdApp = Nothing End Sub "Lonnie M." wrote in message ups.com... Here are a couple of examples that might help you get started. Example of pasting to a new Word document: http://groups.google.com/group/micro...cd865d50a7b808 Example of opening and pasting to the Word document: http://groups.google.com/group/micro...c733e1036c0ba0 HTH--Lonnie M. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I thought this went off yesterday but I cannot see it exept in my Out box:
Martin - thank you for your quick response but something is wrong in the following macro which stops at 'Selection.PasteAndFormat (wdPasteDefault)' It also stops with 'Selection.PasteAndFormat (wdFormatPlainText)' Please help! When it is does run properly I should like to change to using an existing Word document(Calendar.rtf) which already exists in the same folder as the XL sheet. Please also help with the code for that This is the macro which will not run Sub DataFromXLToWord() Dim WrdApp As New Word.Application Dim wrdDoc As New Word.Document 'copy the required data from the Excel File ThisWorkbook.Sheets(1).Range("B2:D10").Copy ' Create a new Word Document Set wrdDoc = WrdApp.Documents.Add(DocumentType:=wdNewBlankDocum ent) WrdApp.Visible = True 'Paste the copied data as table Selection.PasteAndFormat (wdPasteDefault) 'Selection.PasteAndFormat (wdFormatPlainText) 'save the new Word Document wrdDoc.SaveAs "c:\Filename.doc", wdWord 'clean up code wrdDoc.Close Set wrdDoc = Nothing Set WrdApp = Nothing End Sub Francis Hookham ____________________________________________ "Martin Krastev" wrote in message ... 1. To paste as plain text use Selection.PasteAndFormat (wdFormatPlainText) and to paste as table use Selection.PasteAndFormat (wdPasteDefault) 2. Yes, the type library reference is kept with the excel workbook "Francis Hookham" ??????: Many thanks Lonnie and Martin Ok as far opening the Word doc but I am having no luck with pasting in the copied table 1 In this particular case I want the table pasted in but, in the future, I might want to paste as text so can you help with code for both please 2 Is the reference to 'Microsoft Word Object Library' carried by the macro/worksheet of shall I have to set the reference again in another computer - I shall want to send the resulting worksheet to a friend for whom I am writing this Thanks Francis Hookham Sub PasteAsPic() Dim WrdApp As New Word.Application Dim wrdDoc As New Word.Document 'copy the required data from the Excel File ThisWorkbook.Sheets(1).Range("B2:D10").Copy ' Create a new Word Document Set wrdDoc = WrdApp.Documents.Add(DocumentType:=wdNewBlankDocum ent) WrdApp.Visible = True 'Paste the copied data as Picture WrdApp.Selection.PasteSpecial Placement:=wdInLine, DataType:=wdPasteBitmap 'save the new Word Document wrdDoc.SaveAs "c:\Filename.doc", wdWord 'clean up code wrdDoc.Close Set wrdDoc = Nothing Set WrdApp = Nothing End Sub "Lonnie M." wrote in message ups.com... Here are a couple of examples that might help you get started. Example of pasting to a new Word document: http://groups.google.com/group/micro...cd865d50a7b808 Example of opening and pasting to the Word document: http://groups.google.com/group/micro...c733e1036c0ba0 HTH--Lonnie M. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Word Wrap Not Working | Excel Worksheet Functions | |||
HELP! Links in Excel & Word not working | Excel Discussion (Misc queries) | |||
Excel working with Word | Excel Discussion (Misc queries) | |||
Word Wrap not working correctly | Excel Worksheet Functions | |||
word wrap not working | Excel Discussion (Misc queries) |