18. juni 2004 - 14:25Der 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?
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
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
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
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
Synes godt om
Ny brugerNybegynder
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.