copy excel range to word document

Hello,

I would like to copy an excel range "Sheet1. range A1:F35" to a Word document with the following path:

C:\Users\Centa\Trader Journals\TEST\test.docx

The macro should run using Sheet1 as the Active Sheet.
Everytime the macro is run, it should add a new page to the word document

I have included an example of the spreadsheet.

Thanks,
CC
example-copyToWord.xlsm
CC10Asked:
Who is Participating?
 
GrahamSkanRetiredCommented:
Try this general fix for Word problems here:
http://support.microsoft.com/default.aspx/kb/921541
0
 
djsharmaTechnical ConsultantCommented:
0
 
CC10Author Commented:
maybe a misunderstanding. I need a macro that copies the range.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
GrahamSkanRetiredCommented:
Not sure where you are stuck, but you'll need something like this. Don't forget to add a reference to the Microsoft Word Object library.
Sub CopyToWord()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim sh As Worksheet
Dim bNewApp As Boolean

Set sh = ActiveWorkbook.Sheets(1)
sh.Range("A1", "C2").Copy

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
On Error GoTo 0
If wdApp Is Nothing Then
    Set wdApp = CreateObject("Word.Application")
    bNewApp = True
End If
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("C:\MyFolder\Mydoc.docx")
With wdDoc
    .Bookmarks("\EndofDoc").Range.Text = vbFormFeed
    .Bookmarks("\EndofDoc").Range.Paste
    .Close wdSaveChanges
End With
If bNewApp Then
    wdApp.Quit
End If
End Sub

Open in new window

0
 
CC10Author Commented:
I added the reference "Microsoft Word 12.0 Object Library" to the Excel Reference list (ticked the box) but obviously that is not the solution as I get a pop up saying Library not registered. I am not savvy with Word macros. What do I have to do there?
0
 
GrahamSkanRetiredCommented:
It isn't a Word macro, it's written to run in Excel.

Usually if the library isn't referenced, you get a 'Compile error: User-defined type not defined' message when you try to run the code.

I have never seen that error message. Is that the full text? If not, can you report the full message, please.
Is a particular code line highlighted? If so, which line?
0
 
CC10Author Commented:
Error Message:

Run Time error 2147319779 (800280id)
Automation error
Library not registered

At the code line:

at the Set wdApp = createObject ("Word.Application")

If I switch back to the worksheet, it is frozen on the picture of the Logo.
0
 
CC10Author Commented:
I found this on the link you sent me:

Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
322756 How to back up and restore the registry in Windows

    Find the line of code that is failing, for example:

    Server.CreateObject("MSWC.BrowserType")
                                        

    The text string, "MSWC.BrowserType", is the ProgID (Program ID).
    On the Start menu, click Run. At the command prompt, type the following command to start the registry editor:
    RegEdt32.exe
    In the HKEY_CLASSES_ROOT window, click to expand the ProgID key, and then click CLSID. Record the UUID value of this key. For example, the ClassID for "MSWC.BrowserType" is {0ACE4881-8305-11CF-9427-444553540000}.
    In the HKEY_CLASSES_ROOT window, click to expand the CLSID key, and then select the ClassID entry (UUID). On the Security menu, click Permissions. Make sure that the Everyone entry has Read permission; if not, add this permission entry.

I found the PROGiD key for Word.Application, changed the permission but it did not solve the problem.

To be honest, I have no idea what I am doing here!
0
 
CC10Author Commented:
in Word, VB, Tools, References, I have ticked the boxes:

Microsoft Word 12.0 Object Library
Microsoft Excel 12.0 Object Library
Microsoft Office 12.0 Object Library
Microsoft HTML 12.0 Object Library
Visual basis For Applications
OLE Automation

In Excel
I have ticked the same

It still doesn't work
0
 
GrahamSkanRetiredCommented:
You seem to have found this page: http://support.microsoft.com/kb/274038. I did have a look at it, but I didn't post it, because it refers to a similar message in ASP, not Word.

The link that I posted addresses more general problems with Word, and has a Fix-it button to do the job.

If that doesn't work, we'll look at registering some DLLs, but that's a bit more complicated.
0
 
CC10Author Commented:
I tried the Fix it button but that only concentrates on standard stuff, printers, add.ins etc...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.