Consulting

Results 1 to 12 of 12

Thread: Library Not Registered error

  1. #1
    VBAX Regular
    Joined
    Jun 2010
    Posts
    7
    Location

    Library Not Registered error

    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("B195").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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Shouldn't the template name have a file extension, .dot or .dotm or whatever?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jun 2010
    Posts
    7
    Location
    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?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Jun 2010
    Posts
    7
    Location
    Word 12 is not an option on the older version of Office, only 11 is/can be checked.

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    I am sure Bob is way ahead of me, but if you are writing code to use in different versions, why not Late-Binding?

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by GTO
    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
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Regular
    Joined
    Jun 2010
    Posts
    7
    Location
    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
    Last edited by kilgour; 06-15-2010 at 02:43 PM.

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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

    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by xld
    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

  11. #11
    VBAX Regular
    Joined
    Jun 2010
    Posts
    7
    Location

    Smile

    Thank you very much for all the help xld and GTO. Worked perfectly.

    Paul

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by GTO
    My apology and please forgive. I can offer only that it was a frustrating night and I responded too quickly.
    I did a smiley!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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