473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Excel to Word

1
Hey all!

I'm having a problem with transferring data from excel to word. I've got the majority of the code done where I can select and copy the cells in excel and paste the cells as required into word. However I can't specify where I want the data to be inserted into word. When this goes into full operation there will be a lot of data to be transferred. I guess I need to use words bookmarks but I don't want to loose the paste special -> link function.

Any ideas?

Code so far:
Expand|Select|Wrap|Line Numbers
  1. Sub Excel_to_Word()
  2. Dim wdApp As Word.Application, wdDoc As Word.Document, ws As Worksheet
  3.     Application.ScreenUpdating = False
  4.     Application.StatusBar = "Creating new document..."
  5.     Set wdApp = New Word.Application
  6.     Set wdDoc = wdApp.Documents.Open("c:\Doc1.doc")
  7.  
  8.     wdApp.Visible = True
  9.  
  10.     Sheets("Project Data").Range("B1:F16").Copy
  11.  
  12.     wdApp.Selection.PasteSpecial Link:=True, DataType:=wdPasteRTF
  13.  
  14. End Sub
  15.  
Nov 10 '08 #1
1 1791
Dököll
2,364 Expert 2GB
Hey there friend!

This looks to be the same code you have, but it looks your's is missing somehting:

Expand|Select|Wrap|Line Numbers
  1. Sub RangeToDocument()
  2. ' Set a VBE reference to Microsoft Word Object Library
  3.  
  4. Dim WDApp As Word.Application
  5. Dim WDDoc As Word.Document
  6.  
  7. ' Make sure a range is selected
  8. If Not TypeName(Selection) = "Range" Then
  9.     MsgBox "Please select a worksheet range and try again.", vbExclamation, _
  10.         "No Range Selected"
  11. Else
  12.     ' Reference existing instance of Word
  13.     Set WDApp = GetObject(, "Word.Application")
  14.     ' Reference active document
  15.     Set WDDoc = WDApp.ActiveDocument
  16.     ' Reference active slide
  17.  
  18.     ' Copy the range
  19.     Selection.Copy
  20.  
  21.     ' Paste the range
  22.     WDApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteRTF, _
  23.         Placement:= wdInLine, DisplayAsIcon:=False
  24.  
  25.     ' Clean up
  26.     Set WDDoc = Nothing
  27.     Set WDApp = Nothing
  28. End If
  29.  
  30. End Sub
  31.  
  32.  
I bold the portion I think should do the trick for ya...

Let us know if that worked:-)

Whoops, bold does not work, been away too long. Look where you need to paste the data, perhaps you can use it to fit your needs.

Later!
Nov 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
0
by: volume | last post by:
Hi all, In an effort to try to impress the boss, I would like to log accounting information to an Excel spreadsheet using C# and .NET. This would be a mockup only, not a real solution - yet! We...
1
by: Bernd Muent | last post by:
Hi together, I am using the following code in Visual Basic to open Word or Excel applications: Word: Dim w As Word.Application w = CType(CreateObject("Word.application"), Word.Application)...
4
by: Lewis Edward Moten III | last post by:
I have a file that users can download through a web page protected by forms authentication: Download.aspx?ID=45 and within that file ... FileInfo fileToDownload = new FileInfo(fileName);
4
by: Lisa | last post by:
Hi - I'm able to open excel workbooks and word documents, but I can't seem to copy excel charts, named ranges, etc. to a word document. Anyone know of good reference material in this area? What...
1
by: Robin Tucker | last post by:
Heres and interesting problem: I have a VB.NET program that creates reports via. Word Automation. This all works fine. What I want to do as part of this report generation process is to embed a...
3
by: herman404 | last post by:
Hi everyone, I have data coming to me in the form of Word and Excel files, and I need to place this data into a SQL Server database. The Word file will be coming in text which is similiar to an...
6
by: Mark Rae | last post by:
Hi, My client has asked me to provide a "quick and dirty" way to export the contents of a DataGrid to both Excel for analysis and Word for editing and printing, so I'm investigating client-side...
1
by: Cloud | last post by:
Hi all, I have a parent page(parent.aspx) which will open different new windows depending on the user input. for example, the new windows are opened using the following code :...
1
by: webgirl | last post by:
Hi everyone, I have a weird problem with some Word/Excel automation code that I run from Access (not sure if I should therefore post this in the Access forum..? Thought I'd try here first) ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.