Ich versuche einige Werte aus MS Project in MS Excel gezielt zu importieren.
Ich habe es mit der Funktion Find() probiert, aber irgendwie komme ich mit den Set-Anweisungen nicht klar.
Eine Fehlermeldung kommt: Laufzietfehler 91: Objektvariable oder With-Blockvariable nicht festgelegt.
Nachfolgend der Code. Die Linien die offensichtlich falsch sind, habe ich fett markiert.
Ich hoffe dass jemand mir weiter helfen kann. Ich bedanke mich im Voraus.
Beste Grüße, Juan.
Private Sub CmdImportAP_Click()
Dim Datei
Dim mpApp As MSProject.Application
Dim Proj As Project
Dim T As Task
Dim xlCell As Range
Dim Zelle As Range
Dim Spalte As Long
Dim Gesucht As Variant
Dim objSheet As Worksheet
Datei = Application.GetOpenFilename("Microsoft Project Datei (*.mpp), *.mpp")
If Datei = False Then
MsgBox "Keine Datei wurde ausgewählt."
Exit Sub
End If
Sheets(4).Visible = True
Sheets(4).Select
Application.ScreenUpdating = False
For Each Zelle In Worksheets(4).Range("A60:A560").Rows
If Zelle.Hidden = True Then
Zelle.Hidden = False
End If
Next
Set mpApp = New MSProject.Application
mpApp.Visible = False
mpApp.FileOpen Datei
Set objSheet = Worksheets(4)
With objSheet
Gesucht = Range("RangeDatum").Value
Set xlCell = .Range("RangeLaufzeit2").Find(what:=Gesucht, _
LookAt:=xlWhole, LookIn:=xlValues, MatchCase:=False)
Spalte = xlCell.Column
End With
Set xlCell = xlCell.Offset(1, 0)
For Each T In mpApp.ActiveProject.Tasks
If Not T Is Nothing Then
If Not T.Summary Then
xlCell.Value = T.PercentComplete
xlCell.NumberFormat = "General\%"
Set xlCell = xlCell.Offset(1, 0)
End If
End If
Next T
Set objSheet = Nothing
Set xlCell = Nothing
mpApp.FileClose pjDoNotSave
mpApp.Quit
Set mpApp = Nothing
AppActivate "Microsoft Excel"
Cells(61, Spalte).Select
End Sub