Liebes Forum
der folgende code ist auf einem Formularbutton hinterlegt und funktioniert auch. Verwende ich denselben code auf einem anderen Button auf demselben Formular, wird der code 1x richtig ausgefüht, danach bleibt Excel im Taskmanager geöffnet und beim nächsten Aufruf erscheint dann eine Fehlermeldung.
Private Sub Befehl11_Click()
Dim xl As Excel.Application
Dim xlWrkBk As Excel.Workbook
Dim xlsht As Excel.Worksheet
Dim selimportfile As String
selimportfile = "N:\far\import\inkasso-test-2011.xls"
'gewählte Datei öffnen
Set xl = CreateObject("Excel.Application")
Set xlWrkBk = xl.Workbooks.Open(selimportfile)
Set xlsht = xlWrkBk.Worksheets(1)
'$$$
xl.ActiveWorkbook.Save
xl.ActiveWorkbook.SaveAs FileName:="N:\far\Import\inkasso.txt", FileFormat:=xlText, CreateBackup:=False
xlWrkBk.Close False
xl.Quit
Set xlWrkBk = Nothing
Set xlsht = Nothing
Set xl = Nothing
MsgBox "End of xls2txt.", vbInformation, "Excel nach Text..."
End Sub
Ich öffne eine Excel Datei, speichere die Datei und Speichere die Datei zusätzlich als Textdatei.
Besten Dank für eure Hilfe
Hallo
Warum erstellst du xlWrkBk wenn du es nicht verwendest?
....
'$$$
xlWrkBk.Save
xlWrkBk.SaveAs FileName:="N:\far\Import\inkasso.txt", FileFormat:=xlText, CreateBackup:=False
....
ggf musst du noch eine kleine WaitRoutine nach dem Speichern einbauen