View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Closing non EXCEL files

Just as I said, if it is open in excel it it can be treated as a workbook.


Anyway, this workes fine for me:

Sub AAA()
Dim myFilename As Workbook
Workbooks.OpenText FileName:="C:\Data6\mayreport.txt", _
Origin:=xlWindows, _
StartRow:=1, _
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), _
Array(10, 1), _
Array(15, 1), _
Array(24, 1))
Set myFilename = Workbooks("MayReport.txt")
Application.DisplayAlerts = False
myFilename.SaveAs FileName:="C:\Data6\MayReport.csv", _
FileFormat:=xlCSV
Application.DisplayAlerts = True
myFilename.Close SaveChanges:=False

End Sub

Opens a text file, saves it as CSV, closes it.

--
Regards,
Tom Ogilvy



"Grace" wrote in message
...
Just to be clear, it is brought in as a text type file and CSVd. Now I

want
to close it. I tired dimensioning it as a workbook file and that bombed

the
macro out when I tried to open it. So, I dimensioned it as a variant.

Is
there something better than variant I should use?

Whatever you recommend, what command should I use to close it without
saving?

Thx,
Grace

"Tom Ogilvy" wrote in message
...
Regardless, if opened in excel, they can be treated as workbooks.

If myfilename is a string variable with the file name

workbooks(MyfileName).Close SaveChanges:=False

if myFilename is a workbook variable with a reference to the file you

code
should work, so I assume it is the above although I would use

MyFileName.Close SaveChanges:=False in that case

--
Tom Ogilvy


"Grace" wrote in message
...
After opening some text files via CSV and editing, then copying from

them,
I
want to close them. Someone suggested:

myFilename.Saved = True '
myFilename.Close

but it bombed the macro ("object required" error message). And I

suspect
I
did not make it clear that, though they are opened in EXCEL, these are

not,
nor were they ever, EXCEL files. So, perhaps the commands need to be
different.

Can someone suggest revised commands?

Thanks,
Grace