![]() |
Exporting to Word
Hi all,
I work with Spreadsheets almost daily and evertime I finish one I export certain cells to word. I do this by cutting from Excel and pasting in Word. i can not use the linked spreadsheet because the word document is usually sent to the client as an offer. I was hoping someone could either show me some code to export automatically from Excel to word or a good site to see if I can learn how it is done. Thanks in advance Murray |
Exporting to Word
Hi Murray,
afaik there is no possibility to export data automatically into a .doc file because macros just give commands to excel... you could use a macro to open a word .doc and paste the data by giving him the keyboard commands... but I would not prefer that... If it helps you, you could at least use a macro to copy the cells you want - so you just need to open word and press ctrl+v ... therefor you can use range("cell1","cell2").copy Best Markus -----Original Message----- Hi all, I work with Spreadsheets almost daily and evertime I finish one I export certain cells to word. I do this by cutting from Excel and pasting in Word. i can not use the linked spreadsheet because the word document is usually sent to the client as an offer. I was hoping someone could either show me some code to export automatically from Excel to word or a good site to see if I can learn how it is done. Thanks in advance Murray . |
Exporting to Word
Murray
Here's some automation code that opens a Word Application and Document (Set in the code to C:\Test.doc, but could be any word file, even user selected). It then copies the selected cells in Excel and pastes them to the Word Document at the cursor position, saves the word document as test1.doc (Again, could be anything, cell value, date, user selected), closes the document and Excel, releasing the variables used to hold them. It's only a start and needs much refining Important: The code uses early binding and therefore you will need, in your Excel document to open the VBE(Alt+F11), (This is where the code goes) and go to ToolsReferences and check the box next to Microsoft Word xx Library, where xx is your version. Sub ExportSelectionToWord() Dim wd As New Word.Application Dim doc As New Word.Document Dim rng As Range Set wd = New Word.Application Set doc = wd.Documents.Open(Filename:="C:\Test.doc") wd.Visible = True Set rng = Selection rng.Copy wd.Selection.Paste With doc .SaveAs ("C:\Test1.doc") .Close End With Set doc = Nothing wd.Quit Set wd = Nothing End Sub -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England HIS "Murray" wrote in message ... Hi all, I work with Spreadsheets almost daily and evertime I finish one I export certain cells to word. I do this by cutting from Excel and pasting in Word. i can not use the linked spreadsheet because the word document is usually sent to the client as an offer. I was hoping someone could either show me some code to export automatically from Excel to word or a good site to see if I can learn how it is done. Thanks in advance Murray |
All times are GMT +1. The time now is 12:41 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com