[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

copy excel range to word document

Posted on 2013-06-16
11
Medium Priority
?
570 Views
Last Modified: 2013-06-26
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
0
Comment
Question by:CC10
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 9

Expert Comment

by:djsharma
ID: 39251115
0
 

Author Comment

by:CC10
ID: 39251317
maybe a misunderstanding. I need a macro that copies the range.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39252745
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:CC10
ID: 39254007
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39254869
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
 

Author Comment

by:CC10
ID: 39255337
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
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 1200 total points
ID: 39255890
Try this general fix for Word problems here:
http://support.microsoft.com/default.aspx/kb/921541
0
 

Author Comment

by:CC10
ID: 39256409
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
 

Author Comment

by:CC10
ID: 39258989
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39259020
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
 

Author Comment

by:CC10
ID: 39259125
I tried the Fix it button but that only concentrates on standard stuff, printers, add.ins etc...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
New style of hardware planning for Microsoft Exchange server.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question