probably got to do with activeworkbook.
when you are in debugging mode it could be
that "thisworkbook" in which the code runs
is the activeworkbook.
(maybe Omzetten reactivate another workbook..
unlike the open function (which returns a workbook object)
OpenText is a method with no return value.
so assign the variable from activeworkbook just after opening the file.
and pass the workbook variable as an argument to the omzetten procedure.
(and inside the omzetten, change the activeworkbook variables to mybook
Sub x()
Dim myFile$, nwFile$, pathToUse$, pathToSave$
Dim myBook As Workbook
myFile = Dir$(pathToUse & myFile)
Do While myFile < ""
'Open document
Call Workbooks.OpenText(Filename:=pathToUse & myFile, _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(6, 1), Array(37, 1), _
Array(47, 1)))
Set myBook = ActiveWorkbook
'Document Omzetten
Call omzetten(myBook)
'Nieuwe naam geven (XLS)
nwFile = Left(myFile, Len(myFile) - 4)
'Print en Sluit het gewijzigde document na de wijzigingen
With myBook
.PrintOut Copies:=2
.SaveAs Filename:=(pathToSave & nwFile & ".xls"), _
FileFormat:=xlWorkbookNormal
.Close 0
End With
Set myBook = Nothing
'Volgende document in de map
myFile = Dir$()
Loop
Exit Sub
Errorhandler:
MsgBox ( _
"er is een fout opgetreden," & _
" het programma kan niet worden voortgezet. " & vbLf & _
"Bel 212 of ga naar huis!")
End Sub
Sub omzetten(wkb As Workbook)
msgbox wkb.name
End Sub
--
keepITcool
|
www.XLsupport.com | keepITcool chello nl | amsterdam
Rinze Smit wrote :