View Full Version : Library Not Registered error
kilgour
06-15-2010, 10:45 AM
I have written the following code on a computer using Office 2007 which opens a new Word document and pastes some data from the excel document. However when I attempted to use the spreadsheet on another computer with Office 2003 installed I get a "Library not registered" error:
Sub PasteToWord()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim PupilName As String
Set wrdApp = New Word.Application
Set wrdDoc = wrdApp.Documents.Add(Template:="C:\Swimming\Template")
wrdApp.Visible = True
PupilName = getName()
Range("B1:D95").Select
Selection.Copy
With wrdDoc
.Content.Paste
.SaveAs ("C:\Swimming\" + PupilName + " Targets.doc")
End With
End Sub
I have looked at the VBA references and the new version has Microsoft Word 12.0 Object Library ticked and the older version has Microsoft Word 11.0 Object Library ticked.
Can someone please help with the above code so that it will work on both computers.
Many thanks,
Paul
Bob Phillips
06-15-2010, 12:12 PM
Shouldn't the template name have a file extension, .dot or .dotm or whatever?
kilgour
06-15-2010, 12:21 PM
I've added .dot but that hasn't helped. The run time error is happening at the line:
Set wrdApp = New Word.Application
Any ideas?
Bob Phillips
06-15-2010, 12:31 PM
Did you say that you have a reference to two Word versions?
Try unchecking the Word 12 version and run it.
If that fails, re-check Word 12 and uncheck Word 11 and run it.
kilgour
06-15-2010, 01:21 PM
Word 12 is not an option on the older version of Office, only 11 is/can be checked.
I am sure Bob is way ahead of me, but if you are writing code to use in different versions, why not Late-Binding?
Bob Phillips
06-15-2010, 02:21 PM
I am sure Bob is way ahead of me, but if you are writing code to use in different versions, why not Late-Binding?
I was on my way there Mark, going rounabaout route :)
kilgour
06-15-2010, 02:25 PM
Sorry, I am not clear on what late-binding is. Could you please explain the process or give example code that would allow it to work.
I have attempted the following code which I believe is late binding but it fails with the same error:
Sub PasteToWord()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim PupilName As String
'Set wrdApp = New Word.Application
Set wrdApp = CreateObject("Word.Application")
Thanks,
Paul
Bob Phillips
06-15-2010, 02:45 PM
With late-binding, you have no need to set a reference, it is picked up at run-time. It herefore caters for any setup.
Your code would look like
Sub PasteToWord()
Dim wrdApp As Object
Dim wrdDoc As Object
Dim PupilName As String
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add(Template:="C:\Swimming\Template")
wrdApp.Visible = True
PupilName = getName()
Range("B195").Copy
With wrdDoc
.Content.Paste
.SaveAs ("C:\Swimming\" + PupilName + " Targets.doc")
End With
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
I was on my way there Mark, going rounabaout route :)
My apology and please forgive. I can offer only that it was a frustrating night and I responded too quickly.
A great day to you and yours mate,
Mark
kilgour
06-15-2010, 03:06 PM
Thank you very much for all the help xld and GTO. Worked perfectly.
Paul
Bob Phillips
06-15-2010, 03:19 PM
My apology and please forgive. I can offer only that it was a frustrating night and I responded too quickly.
I did a smiley!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.