Gruppe
Allgemein
Problem
Über einen Dialog wird eine Quelldatei ausgewählt. In das Import-Blatt werden die Werte der in Spalte A genannten Zellen aus dem Blatt Tabelle1 der Quelldatei importiert.
StandardModule: Modul1
Sub CopyValues()
Dim vFile As Variant
Dim iRow As Integer
Dim sPath As String, sFormula As String, sMem As String, sRange As String
sPath = "c:\temp"
sMem = CurDir
ChDrive Left(sPath, 1)
ChDir sPath
vFile = Application.GetOpenFilename("Excel-Arbeitsmappen (*.xls), *.xls")
If vFile = False Then Exit Sub
sFormula = "='" & sPath & "\[" & Dir(vFile) & "]Tabelle1'!" & Range("A1").Value
With Worksheets("Import")
.Range(Range("A1").Value).FormulaLocal = sFormula
iRow = 2
Do Until IsEmpty(Cells(iRow, 1))
If iRow = 2 Then
sRange = Cells(iRow, 1).Value
Else
sRange = sRange & "," & Cells(iRow, 1).Value
End If
iRow = iRow + 1
Loop
.Range(Range("A1").Value).Copy .Range(sRange)
.UsedRange.Value = .UsedRange.Value
Application.CutCopyMode = False
End With
ChDrive Left(sMem, 1)
ChDir sMem
MsgBox "Job erledigt!"
End Sub