var fileNames = {
path: "C:/temp",
infile: "excelfile.xls",
outfile: "excelfile2.xls"
};
WScript.Echo( openExcelFile( fileNames.path + "/" + fileNames.infile ) );
function openExcelFile( fileName )
{
var excelApp = new ActiveXObject("Excel.Application");
var wbin = excelApp.Workbooks.Open( fileName );
var wbout = excelApp.Workbooks.Add();
var currentRange, currentCell, x, y;
var out = new Array();
if( wbin.Sheets.Count > 0 )
{
currentRange = wbin.Sheets(1).UsedRange;
for ( y = 0; y < currentRange.Rows.Count; y++ )
{
for ( x = 0; x < currentRange.Columns.Count; x++ )
{
currentCell = currentRange.Cells( y + 1, x + 1 ).Text;
out.push( currentCell );
wbout.ActiveSheet.Cells( y + 1, x + 1 ).Value = currentCell
}
}
}
wbout.SaveAs( fileNames.path + "/" + fileNames.outfile );
//wbin.Close();
//wbout.Close();
excelApp.Quit();
return out.join(" | ");
}Option Explicit
Private Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" ( _
ByVal lpFileName As String, _
ByRef lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" ( _
ByVal hFindFile As Long, _
ByRef lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32.dll" ( _
ByVal hFindFile As Long) As Long
Private Enum FILE_ATTRIBUTE
FILE_ATTRIBUTE_READONLY = &H1
FILE_ATTRIBUTE_HIDDEN = &H2
FILE_ATTRIBUTE_SYSTEM = &H4
FILE_ATTRIBUTE_DIRECTORY = &H10
FILE_ATTRIBUTE_ARCHIVE = &H20
FILE_ATTRIBUTE_NORMAL = &H80
FILE_ATTRIBUTE_TEMPORARY = &H100
End Enum
Private Const MAX_PATH = 260
Private Const INVALID_HANDLE_VALUE = -1
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Public Sub Start()
Dim vntFolders As Variant
Dim lngIndex As Long
vntFolders = Folderlist(ThisWorkbook.Path)
If IsArray(vntFolders) Then
For lngIndex = LBound(vntFolders) To UBound(vntFolders)
Dim DateiName As String
DateiName = Dir(vntFolders(lngIndex) & "\*.xls")
Do While DateiName <> ""
If ThisWorkbook.Name <> DateiName Then
Workbooks.Open Filename:=vntFolders(lngIndex) & "\" & DateiName
Workbooks(DateiName).Worksheets(1).Range("A1").Copy _
ThisWorkbook.Worksheets(1).Range("A" & ThisWorkbook.Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row + 1)
Workbooks(DateiName).Close
End If
DateiName = Dir
Loop
Next
End If
End Sub
Private Function Folderlist(ByVal strFolderPath As String) As Variant
Dim WFD As WIN32_FIND_DATA
Dim lngSearch As Long, lngCounter As Long
Dim strDirName As String
Dim vntFolderArray() As Variant
If Right$(strFolderPath, 1) <> "\" Then strFolderPath = strFolderPath & "\"
lngSearch = FindFirstFile(strFolderPath & "*", WFD)
If lngSearch <> INVALID_HANDLE_VALUE Then
Do
If CBool(WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
strDirName = Left$(WFD.cFileName, InStr(WFD.cFileName & vbNullChar, vbNullChar) - 1)
If (strDirName <> ".") And (strDirName <> "..") Then
lngCounter = lngCounter + 1
ReDim Preserve vntFolderArray(1 To lngCounter)
vntFolderArray(lngCounter) = strFolderPath & strDirName
End If
End If
Loop While FindNextFile(lngSearch, WFD)
FindClose lngSearch
Folderlist = vntFolderArray
End If
End Function
komma nachträglich in excel spalten
haette 08.02.2008 - 76 Hits - 3 Antworten
Spalten Einblenden in Excel
putzi 15.04.2008 - 159 Hits - 4 Antworten
Mehr Spalten in Excel
jjgwlw 04.08.2008 - 9 Hits - 2 Antworten
Messwerterfassung, mehrere Dateien zusammenkopieren
Andreas98 23.10.2008 - 16 Hits - 2 Antworten
Excel Spalten ausblenden
michael87 27.02.2009 - 1310 Hits - 2 Antworten