+ Reply to Thread
Results 1 to 3 of 3

How to transfer data from Excel to Word

Hybrid View

  1. #1
    Registered User
    Join Date
    07-13-2004
    Posts
    11

    How to transfer data from Excel to Word

    I have Excel spreadsheet with data that I would like to put in MS Word for better presentation. I know that I can simply cut and paste the Excel cell into Ms Word as a table.

    Instead, I want to be able to transfer the data in each cell in Excel to Ms Word in form format. To accomplish this I wrote Excel macro to write data from Excel into a text file.

    Sub WriteToFile()
    Application.Goto reference:=Worksheets("Cases").Range("A6")
    
    Open "c:\temp\ufos.txt" For Output As #1
    
    k = 6
    n = 116
    n = n - k + 1
    
    For i = 1 To n
        nm = ActiveCell.Value
        Print #1, "Name of Event: "; nm
        lc = ActiveCell.Offset(0, 1).Value + ", " + ActiveCell.Offset(0, 2).Value
        Print #1, "Location: "; lc
        dt = ActiveCell.Offset(0, 8).Value
        Print #1, "Date: "; Format(dt, "mmmm dd, yyyy")
        tm = ActiveCell.Offset(0, 11).Value
        Print #1, "Time: "; tm
        te = ActiveCell.Offset(0, 5).Value
        Print #1, "Type of Encounter: "; te
        sp = ActiveCell.Offset(0, 6).Value
        Print #1, "Shape: "; sp
        dsc = ActiveCell.Offset(0, 12).Value
        Print #1, "Description: "; dsc
        
        ActiveCell.Offset(1, 0).Activate
        Print #1,
        Print #1,
    Next i
    Close #1
    End Sub
    My question now is how do I format each of the entries. For example I want to be able to bold field name.
    I also want to indent each of the lines under the "Description" field.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,494

    Re: How to transfer data from Excel to Word

    You can't. The clue is in the type of file you are creating ... a TEXT file.

    I think you'd need to write a macro to open a Word document and write direct to that.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How to transfer data from Excel to Word

    surely youd design the word document to look good and use mail merge to fill in the data
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1