Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
This is an excerpt of some code I have been working on: -------start------------ FileToOpen = Application.GetOpenFilename If FileToOpen < False Then 'Set path path = Left(FileToOpen, InStrRev(FileToOpen, "\")) 'Open connection to file cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";Extended Properties='text;HDR=NO;FMT=Delimited'" 'Set file file = Right(FileToOpen, Len(FileToOpen) - InStrRev(FileToOpen, "\")) 'Open recordset with Earnie data rsEarnie.Open "Select * From " + file, cn, adOpenStatic, adLockReadOnly, adCmdText -------end------------ It works fine when the source file has an extension of "txt", but I want it to work regardless of the extension. The file that will be selected will be produced by our payroll package and is created as payroll.001 or payroll.002. Rather than ask users to rename the file with a "txt" extension, is there a way to read the data in the file as text without the file explicitly being named as a text file? I have tried adCmdUnknown and all the others but they don't work. I get: "Run-time error'-2147217911 (80040e09': Automation error" Any ideas? TIA Jarryd |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Well, you did say *-any-* ideas... Copy the file with the odd extension, save it as a file with a .txt extension, read that file, then delete it. Or, if no one else is going to try to use the payroll files while you are messing with them, just rename them to something like payroll.001.txt and then rename them back when you are through Lots of work - and slow - but if the .Open syntax is going to require a .txt extension, you may not find a better way. Good luck on it, though. Actually, I searched for jet odbc text file extension "not txt" and got an instructive hit at 'Much ADO About Text Files' (http://msdn.microsoft.com/en-us/library/ms974559.aspx) but I don't know if you want to get into registry editing on every PC that might need to read the payroll files... -- jamescox ------------------------------------------------------------------------ jamescox's Profile: http://www.thecodecage.com/forumz/member.php?userid=449 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=126727 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Excellent response. I did try renaming and filecopy to a txt file, etc. but
I hit permissions issues cos you can't always be sure that Excel has rights to the payroll file location. Seems to be a common problem. To be totally honest I need to research more of the workarounds and see if there is a solid one out there that works for all (or almost all) scenarios. I will read the msdn article and have a think about it. I wish there was a way to tell this idiot payroll system how to dump output files, but anyway. Thanks again. Jarryd "jamescox" wrote in message ... Well, you did say *-any-* ideas... Copy the file with the odd extension, save it as a file with a .txt extension, read that file, then delete it. Or, if no one else is going to try to use the payroll files while you are messing with them, just rename them to something like payroll.001.txt and then rename them back when you are through Lots of work - and slow - but if the .Open syntax is going to require a txt extension, you may not find a better way. Good luck on it, though. Actually, I searched for jet odbc text file extension "not txt" and got an instructive hit at 'Much ADO About Text Files' (http://msdn.microsoft.com/en-us/library/ms974559.aspx) but I don't know if you want to get into registry editing on every PC that might need to read the payroll files... -- jamescox ------------------------------------------------------------------------ jamescox's Profile: http://www.thecodecage.com/forumz/member.php?userid=449 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=126727 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all,
I have worked out that using the user TEMP folder to copy the file to as a txt works. Sorting out the code now and will post when done so it can be used if someone needs it. Jarryd "Jarryd" wrote in message ... Excellent response. I did try renaming and filecopy to a txt file, etc. but I hit permissions issues cos you can't always be sure that Excel has rights to the payroll file location. Seems to be a common problem. To be totally honest I need to research more of the workarounds and see if there is a solid one out there that works for all (or almost all) scenarios. I will read the msdn article and have a think about it. I wish there was a way to tell this idiot payroll system how to dump output files, but anyway. Thanks again. Jarryd "jamescox" wrote in message ... Well, you did say *-any-* ideas... Copy the file with the odd extension, save it as a file with a .txt extension, read that file, then delete it. Or, if no one else is going to try to use the payroll files while you are messing with them, just rename them to something like payroll.001.txt and then rename them back when you are through Lots of work - and slow - but if the .Open syntax is going to require a txt extension, you may not find a better way. Good luck on it, though. Actually, I searched for jet odbc text file extension "not txt" and got an instructive hit at 'Much ADO About Text Files' (http://msdn.microsoft.com/en-us/library/ms974559.aspx) but I don't know if you want to get into registry editing on every PC that might need to read the payroll files... -- jamescox ------------------------------------------------------------------------ jamescox's Profile: http://www.thecodecage.com/forumz/member.php?userid=449 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=126727 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all,
This is what I came up with: ----------Start---------- Sub... Dim cn As New ADODB.Connection Dim rsEarnie As New ADODB.Recordset Dim iLastRow As Integer Dim sPathUser As String FileToOpen = Application.GetOpenFilename If FileToOpen < False Then 'Get TEMP path and copy FileToOpen to it sPathUser = Environ$("TEMP") FileCopy FileToOpen, sPathUser + "\payroll.txt" 'Open connection to file cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPathUser & ";Extended _ Properties='text;HDR=NO;FMT=Delimited'" 'Open recordset with Earnie data rsEarnie.Open "Select * From payroll.txt", cn, adOpenStatic, adLockReadOnly, adCmdText .... rsEarnie.Close cn.Close Kill (sPathUser + "\payroll.txt") End If End Sub ----------End---------- HTH someone. Cheers, Jarryd "Jarryd" wrote in message ... Hi all, I have worked out that using the user TEMP folder to copy the file to as a txt works. Sorting out the code now and will post when done so it can be used if someone needs it. Jarryd "Jarryd" wrote in message ... Excellent response. I did try renaming and filecopy to a txt file, etc. but I hit permissions issues cos you can't always be sure that Excel has rights to the payroll file location. Seems to be a common problem. To be totally honest I need to research more of the workarounds and see if there is a solid one out there that works for all (or almost all) scenarios. I will read the msdn article and have a think about it. I wish there was a way to tell this idiot payroll system how to dump output files, but anyway. Thanks again. Jarryd "jamescox" wrote in message ... Well, you did say *-any-* ideas... Copy the file with the odd extension, save it as a file with a .txt extension, read that file, then delete it. Or, if no one else is going to try to use the payroll files while you are messing with them, just rename them to something like payroll.001.txt and then rename them back when you are through Lots of work - and slow - but if the .Open syntax is going to require a txt extension, you may not find a better way. Good luck on it, though. Actually, I searched for jet odbc text file extension "not txt" and got an instructive hit at 'Much ADO About Text Files' (http://msdn.microsoft.com/en-us/library/ms974559.aspx) but I don't know if you want to get into registry editing on every PC that might need to read the payroll files... -- jamescox ------------------------------------------------------------------------ jamescox's Profile: http://www.thecodecage.com/forumz/member.php?userid=449 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=126727 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Read of excel spreadsheet with ADO recordset | Excel Programming | |||
help with macro to read and sort data from multiple text files | Excel Programming | |||
ADO recordset closed, cannot read | Excel Programming | |||
How to read multiple text files into excel? | Excel Programming | |||
Read/Write data to/from text files from a spreadsheet. | Excel Programming |