Avatar billede kedde65 Praktikant
18. juni 2004 - 14:25 Der er 6 kommentarer og
1 løsning

Sæt reference runtime

jeg har en excel applikation der skal fungere ved både version XP og 2003. Jeg har det lille problem at applikationen indeholder en reference til Word 2003, og den kan den naturligvis ikke finde på en Office XP maskine.

I Access der kan man sætte en reference runtime, vha. application.references.add eller noget lign. Kan det også lade sig gøre i Excel?

VH CK
Avatar billede bak Forsker
18. juni 2004 - 14:35 #1
test lige denne her:

Sub VersionTry()
  Dim strReference As String
  On Error Resume Next
  If Left(Application.Version, 1) = 8 Then
  With ActiveWorkbook.VBProject.References
      .Remove ThisWorkbook.VBProject.References _
        ("Microsoft Word 10.0 Object Library")
        strReference = _
            "c:\program files\microsoft office\office\msoutl8.dll"
        .AddFromFile strReference
      End With
  ElseIf Left(Application.Version, 1) = 9 Then
      With ActiveWorkbook.VBProject.References
        .Remove ThisWorkbook.VBProject.References _
            ("Microsoft Word 11.0 Object Library")
        strReference = _
            "c:\program files\microsoft office\office\msoutl9.dll"
        .AddFromFile strReference
      End With
    Else
    MsgBox "This code was not written for Excel Version " & Application.Version
  End If
End Sub
Avatar billede bak Forsker
18. juni 2004 - 14:36 #2
Sorry

Sub VersionTry()
  Dim strReference As String
  On Error Resume Next
  If Left(Application.Version, 1) = 10 Then
  With ActiveWorkbook.VBProject.References
      .Remove ThisWorkbook.VBProject.References _
        ("Microsoft Word 10.0 Object Library")
        strReference = _
            "c:\program files\microsoft office\office\msoutl8.dll"
        .AddFromFile strReference
      End With
  ElseIf Left(Application.Version, 1) = 11 Then
      With ActiveWorkbook.VBProject.References
        .Remove ThisWorkbook.VBProject.References _
            ("Microsoft Word 11.0 Object Library")
        strReference = _
            "c:\program files\microsoft office\office\msoutl9.dll"
        .AddFromFile strReference
      End With
    Else
    MsgBox "This code was not written for Excel Version " & Application.Version
  End If
End Sub
Avatar billede kedde65 Praktikant
18. juni 2004 - 14:38 #3
Fin t nok, jeg har fået ideen til hvor jeg skal lede. Så er jeg på sporet :-)
Avatar billede bak Forsker
18. juni 2004 - 14:38 #4
pokkers fejl igen, vent lidt
Avatar billede kedde65 Praktikant
18. juni 2004 - 14:39 #5
Det er lige meget.. jeg er på sporet :-)
Avatar billede bak Forsker
18. juni 2004 - 14:56 #6
Fint kedde

Sub VersionTry()
  Dim strReference As String
  On Error Resume Next
  If Left(Application.Version, 1) = 10 Then
  With ActiveWorkbook.VBProject.References
      .Remove ThisWorkbook.VBProject.References("Word")
        strReference = "c:\program files\microsoft office\office\msword10.olb"
        .AddFromFile strReference
      End With
  ElseIf Left(Application.Version, 1) = 11 Then
 
      With ActiveWorkbook.VBProject.References
        .Remove ThisWorkbook.VBProject.References("Word")
        strReference = "c:\program files\microsoft office\office\msword11.olb"
        .AddFromFile strReference
      End With
    Else
    MsgBox "This code was not written for Excel Version " & Application.Version
  End If
End Sub
Avatar billede bak Forsker
18. juni 2004 - 15:19 #7
Kunne ikke rigtig stoppe det :-)

Sub LoadCorrectWordVersion()
Dim strReference As String
Dim strVersion As String
strVersion = Left(Application.Version, InStr(1, Application.Version, ".") - 1)
On Error Resume Next
With ActiveWorkbook.VBProject.References
    .Remove ActiveWorkbook.VBProject.References("Word")
    strReference = "c:\program files\microsoft office\office\msword" & strVersion & ".olb"
    .AddFromFile strReference
End With
End Sub
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Excel kurser for alle niveauer og behov – find det kursus, der passer til dig

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester