Daten aus geschl. Arbeitsblättern
02.03.2005 11:21:46
Detlef
mein Problem wurde schon oft beschrieben, habe auch die Excel-CD durchsucht, aber nicht das richtige gefunden.
Problem: in Datei "test.xls" sollen bestimmte Zellinhalte z.B. A5,B3,C4 aus Datei test1.xls (geschlossen) Zeilenweise eingetragen werden. Ich habe bereits eine sehr umfangreiche Funktion gefunden:
Option Explicit
Private Declare Function GetFileNameFromBrowseW Lib "shell32" Alias "#63" (ByVal hwndOwner As Long, ByVal lpstrFile As Long, ByVal nMaxFile As Long, ByVal lpstrInitialDir As Long, ByVal lpstrDefExt As Long, ByVal lpstrFilter As Long, ByVal lpstrTitle As Long) As Long
Private Declare Function GetFileNameFromBrowseA Lib "shell32" Alias "#63" (ByVal hwndOwner As Long, ByVal lpstrFile As String, ByVal nMaxFile As Long, ByVal lpstrInitialDir As String, ByVal lpstrDefExt As String, ByVal lpstrFilter As String, ByVal lpstrTitle As String) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Public Sub Importieren()
Dim intColumn As Integer, lngRow As Long, strFile As String, strFilename As String, strPath As String
Dim myFileSystemObject As Object
strFile = Space(255)
If IsWinNT Then
GetFileNameFromBrowseW FindWindow("XLMAIN", vbNullString), StrPtr(strFile), 255, StrPtr("C:\dre4we\test"), StrPtr("xls"), StrPtr("Exceldateien (*.xls)" + Chr$(0) + "*.xls" + Chr$(0)), StrPtr("Auswählen")
Else
GetFileNameFromBrowseA FindWindow("XLMAIN", vbNullString), strFile, 255, "C:\dre4we\test", "xls", "Exceldateien (*.xls)" + Chr$(0) + "*.xls" + Chr$(0), "Auswählen"
End If
strFile = Trim$(strFile)
If Len(strFile) > 1 Then
Application.ScreenUpdating = False
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
strFilename = myFileSystemObject.GetFile(strFile).Name
strPath = myFileSystemObject.GetFile(strFile).ParentFolder
Set myFileSystemObject = Nothing
With Worksheets("Tabelle1")
lngRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
For intColumn = 2 To 25
.Cells(lngRow, intColumn - 1) = ExecuteExcel4Macro("'" & strPath & "\[" & strFilename & "]Daten'!" & Cells(2, intColumn).Range("A1").Address(, , xlR1C1))
Next
End With
Application.ScreenUpdating = True
End If
End Sub
Private Function IsWinNT() As Boolean
Dim myOS As OSVERSIONINFO
myOS.dwOSVersionInfoSize = Len(myOS)
GetVersionEx myOS
IsWinNT = (myOS.dwPlatformId = 2)
End Function
Dies ist bis zur Auswahl der Datei nicht schlecht.
Aber wie kann ich jetzt die Zellen definieren die ich auslesen will.
Kann mir da einer von Euch weiter helfen?
Bin für jede Antwort dankbar!!!!