Hallo zusammen
Ich rufe innerhalb Workbook_Open() Daten aus einem geschlossenem Workbook auf, das funktioniert auch wunderbar. Dann habe ich noch eine Funktion, die innerhalb eines Macros aufgerufen wird, innerhalb dieser ich wieder auf dasselbe Workbook zugreife, und hier bekomme ich den Laufzeitfehler '1004': Die Methode 'Open' für das Object 'Workbooks' ist fehlgeschlagen. Den Code dafür findet ihr unterhalb.
Man muss dazu sagen, dass alles prima funktioniert, wenn ich das lokal auf meinem PC ausführe. Sobald ich das auf einen Sharepoint hochlade kommt oben genannter Fehler (also wenn URLs genutzt werden). Allerdings verstehe ich nicht weshalb er das Workbook beim zweiten Mal nicht mehr öffnen kann, es zu Beginn in der Workbook_Open() jedoch fehlerfrei funktioniert.
Könnt ihr mir hier helfen, das wäre echt super genial!!!
__________________________________________________________________________
Private Sub Workbook_Open()
Dim FileNameList As String
Dim IS_ListItems As Variant
Dim CPU_ListItems As Variant
Dim i As Integer
Dim j As Integer
Dim IS_SourceWB As Workbook
Dim CPU_SourceWB As Workbook
Sheets("CPU & Memory").CPU_ComboBox.Clear
Sheets("Integration Server").IS_ComboBox.Clear
FileNameList = ThisWorkbook.path + "\File_properties.xls"
With Sheets("Integration Server").IS_ComboBox
.Clear ' remove existing entries from the listbox
' turn screen updating off,
' prevent the user from seeing the source workbook being opened
Application.ScreenUpdating = False
' open the source workbook as ReadOnly
Set IS_SourceWB = Workbooks.Open(FileNameList, False, True)
'IS_ListItems = IS_SourceWB.Worksheets(1).Range("A4:A6").Value
IS_ListItems = IS_SourceWB.Worksheets(1).Range("A7:A" & Cells(Rows.Count, 1).End(xlUp).Row).Value
' get the values you want
IS_SourceWB.Close False ' close the source workbook without saving changes
Set IS_SourceWB = Nothing
Application.ScreenUpdating = True
IS_ListItems = Application.WorksheetFunction.Transpose(IS_ListItems)
' convert values to a vertical array
For i = 1 To UBound(IS_ListItems)
.AddItem IS_ListItems(i) ' populate the listbox
Next i
.ListIndex = 0 ' set to 0 to select the first item
End With
________________________________________________
Function GetPiInstanceVersion(sFile As String) As String
' Function GetPiInstanceVersion
' ================================================================================================
' This function gets the current version of the PI system
' Depending on the version several import parameters change in Macros: MACRO_IS and MACRO_CPU
' Therefore the version is deposited within the File_properties.xls
' Start line has to be line 8 all other extensions are flexible
'
' Author: Karoline Kastner
' Last changes: 07.08.2007
' ================================================================================================
Dim PiInstanceProperties As String
Dim SID As String
Dim k As Integer
Dim PI_SourceWB As Workbook
Dim lineCount As Integer
Dim piINSTVersion As String
PiInstanceProperties = ThisWorkbook.path + "/File_properties.xls"
SID = Mid(sFile, 1, 3)
Application.ScreenUpdating = False
Do While True
Set PI_SourceWB = Workbooks.Open(Filename:=PiInstanceProperties, ReadOnly:=True)
lineCount = PI_SourceWB.Worksheets(2).Cells(Rows.Count, 2).End(xlUp).Row
For k = 8 To lineCount + 1
If PI_SourceWB.Worksheets(2).Cells(k, 2) = SID Then
piINSTVersion = Worksheets(2).Cells(k, 3)
Exit Do
End If
Next k
Loop
PI_SourceWB.Close False
Set PI_SourceWB = Nothing
Application.ScreenUpdating = True
GetPiInstanceVersion = piINSTVersion
End Function
|