folgendes Problem: Ich öffne per VBScript ein Textfile in Excel, welches aber als .xls abgespeichert ist. Jetzt bereite ich es auf und will es dann auch autamitisch mit
xlbook.SaveAs("C:\Temp\Mdv\down2.txt")
abspeichern.
Dann kommt aber die Meldung, das diese Datei schon geöffnet sei, aber das ist sie nicht! Hier der Code:
downpath = "C:\Temp\Mdv\down1.xls"
ExcelCreatedPfad = "C:\Temp\Mdv\down2.xls"
set excel = CreateObject("Excel.Application")
' ########### Open the downloaded text file #########
set xlbook = excel.Workbooks.Open(downpath)
'10
Set ex = xlBook.ActiveSheet
Set ps = ex.PageSetup
'########### Makes the Page setup: headers ( Voith + title of the subject) ####
ps.LeftHeader = "&""Arial Black,Fett""&21VOITH PAPER"
ps.RightFooter = _
"&""Arial Black,Fett""&21VOITH" & Chr(10) & "&""Arial,Standard""&6GROUP OF COMPANIES"
'20
ps.CenterFooter = "Page &P"
ps.Orientation = 2 '2 = xlLandscape => page orientated horizontaly
excel.Columns("A:E").Select
excel.Selection.HorizontalAlignment = -4131 'Alignment on the left of each cell
ex.Rows("1:1").ClearContents
ex.Range("A1:E1").Interior.ColorIndex = 5
ex.Rows("1:1").RowHeight = 2
'30
ex.Rows("2").Font.Bold = True
ex.Rows("2:3").RowHeight = 12.75
ex.Rows("4").ClearContents
ex.Range("A4:E4").Interior.ColorIndex = 5
ex.Rows("4:4").RowHeight = 2
ex.Rows("5").Font.Bold = True
ex.Columns("A:E").WrapText = True
'40
ex.Columns("B:B").EntireColumn.NumberFormat = "yyyy-mm-dd"
ex.Columns("A:E").ColumnWidth = 22
HoeheIni = 29.5 'HöheIni height after the title on the top of each page(2*12.75+2*2)
Hoehe = HoeheIni 'Höhe = Height of the actual cell in the page
HoeheLimit = 420 'HöheLimit = Limit height to make a page break
Offset = 5
TotalRows = ex.UsedRange.Rows.Count ' Get the total number of rows used
'50
Do While Offset <= TotalRows
If ex.Range("A" & Offset).Value = "L1" Then
ex.Rows(Offset).ClearContents
ex.Range("A" & Offset & ":E" & Offset).Interior.ColorIndex = 5
ex.Rows(Offset).RowHeight = 0.75
If Hoehe > HoeheLimit Then
Offset = Offset + 1
'60
With xlBook.ActiveSheet
.HPageBreaks.Add .Range("A" & Offset)
End With
ex.Rows("1:4").Copy
ex.Rows(Offset).Select
'70
xlBook.ActiveSheet.Paste
Hoehe = HoeheIni 'Initialise the height for the new page
Offset = Offset + 3
TotalRows = TotalRows + 4
End If
ex.Rows(Offset + 1).Font.Bold = True
'80
Else
ex.Rows(Offset).EntireRow.AutoFit
End If
ZeileHoehe = ex.Rows(Offset).RowHeight
Hoehe = Hoehe + ZeileHoehe
Offset = Offset + 1
Loop
'90
xlbook.SaveAs("C:\Temp\Mdv\down2.xls")
xlbook.Close
excel.Quit
Set ex = Nothing
Hilfe!!!