+ Reply to Thread
Results 1 to 4 of 4

Excel References and Object libraries

  1. #1
    Registered User
    Join Date
    09-07-2009
    Location
    Lytham, England
    MS-Off Ver
    Excel 2003+07
    Posts
    75

    Excel References and Object libraries

    Hi,
    I have an issue where I set up a shared spreadsheet which is used by Excel 2003 and Excel 2010 users.

    If someone who uses 2010 saves the spreadsheet it no longer becomes usable for 2003 users due to it now using 12.0 instead of 11.0 references (There is a reference to Word in there due to a macro which creates some letters for the user).

    My question is, is there a way of assigning the relevant references to the user when they open the spreadsheet depending on which Excel they are running?

    Many thanks
    Paul

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Excel References and Object libraries

    Paul

    You could rewrite the code that automates Word to use late-binding which doesn't require a reference.

    That isn't as difficult as it sounds, mainly it would involve changing declarations, for example declaring as Object instead of Word.Application, and adding constant declarations for Word constants.

    The advantage of using late-binding would be that the code would work whatever version of Excel/Word/Office the user has.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-07-2009
    Location
    Lytham, England
    MS-Off Ver
    Excel 2003+07
    Posts
    75

    Re: Excel References and Object libraries

    Thanks for the quick reply Norie,

    I'm not much of an expert on this type of code but the way it is coded at the moment is as follows (I think I have the relevant bits);

    Private Sub cmdOK_Click()
    On Error GoTo Errorhandler

    txtAmount = FormatCurrency(txtAmount, 2, IncludeLeadingDigit:=vbTrue)

    'checks all details completed
    AllCompleted = False
    Call CheckCompleted
    If AllCompleted = True Then Exit Sub

    'create new word session if none running
    'Dim appWd As Word.Application
    Set appWd = GetObject(, "Word.Application")
    If appWd <> "Microsoft Word" Then
    Set appWd = New Word.Application
    End If

    'Set appWd = CreateObject("Word.Application")
    appWd.Visible = True

    'Filepath
    GPRdoc = Range("GPRPath")

    'disable word macros
    appWd.WordBasic.DisableAutoMacros 1

    'create GPR
    Set wrddoc = appWd.Documents.Add(GPRdoc)

    'show GPR
    appWd.Activate

    'disable word macros
    appWd.WordBasic.DisableAutoMacros 0

    'insert details
    With wrddoc

    'Inserts Our ref
    If .Bookmarks.Exists("Our_Ref") = True Then
    .Bookmarks("Our_Ref").Range.InsertAfter txtOurRef
    End If


    Would this be classed as late-binding/declaring the object? If not do you please have any tips of where to change this code?

    Many Thanks

    BTW really sorry I can't add code tags - the forum doesn't work for me at work (IE7!) so am try to struggle along using my phone at the moment.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Excel References and Object libraries

    Paul

    That almost looks like it's using late-binding.

    The only part that isn't is this, which uses New Word.Application.
    Please Login or Register  to view this content.
    I think that if you replaced that code with this it might be all you need
    Please Login or Register  to view this content.
    Mind you I've a feeling that isn't all the code, unless you are creating really short letters.

    Is there more?

+ 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