Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open file to write and read at the same time
http://support.microsoft.com/support...eio/fileio.asp
File Access with Visual Basic® for Applications Pretty vague just to say it doesn't work and put up 17 lines of code. Pehaps the above will give you some ideas. -- Regards, Tom Ogilvy mandy_less wrote in message ... Hi all, I'm trying to read the first line of a text file and write some lines to the same file if the file exists. Have tried the codes below but doesnt work! Start of code... ============================================= hFile = FreeFile 'Get the next free file handle nFile = FreeFile attachmentpath = "C:\test.txt" If Len(Dir(attachmentpath)) = 0 Then Open attachmentpath For Output Access Write Shared As _ hFile Print #hFile, "test msg" , strInput Else Open attachmentpath For Input Access Read Shared As _ nFile Line Input #nFile, strline Close #nFile Open attachmentpath For Output Access Write Lock Read _ Write As hFile Print #hFile, "test msg" , strInput End If Close hFile Close nFile ============================================== End of code... Thanks in advance ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open file to write and read at the same time
Hi again,
My intention is to read the 1st line from the text file using the following code: OPEN ATTACHMENTPATH FOR INPUT ACCESS READ SHARED AS _ NFILE LINE INPUT #NFILE, STRLINE CLOSE #NFILE '...(1) [/b] AND WRITE TO THE SAME FILE USING THESE CODES: [b]OPEN ATTACHMENTPATH FOR OUTPUT ACCESS WRITE LOCK READ _ WRITE AS HFILE PRINT #HFILE, \"TEST MSG\" , STRINPUT '...(2) However, the message from (2) is not written to the text file even though I have closed the file (1) and re-opened it for writing (2). Thanks again!!! ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open file to write and read at the same time
Notice how you use
#Nfile in the first command and just Hfile in the second. shouldn't it be #Hfile. -- Regards, Tom Ogilvy "mandy_less" wrote in message ... Hi again, My intention is to read the 1st line from the text file using the following code: OPEN ATTACHMENTPATH FOR INPUT ACCESS READ SHARED AS _ NFILE LINE INPUT #NFILE, STRLINE CLOSE #NFILE '...(1) [/b] AND WRITE TO THE SAME FILE USING THESE CODES: [b]OPEN ATTACHMENTPATH FOR OUTPUT ACCESS WRITE LOCK READ _ WRITE AS HFILE PRINT #HFILE, \"TEST MSG\" , STRINPUT '...(2) However, the message from (2) is not written to the text file even though I have closed the file (1) and re-opened it for writing (2). Thanks again!!! ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how can i open the write protected excel file? | Excel Discussion (Misc queries) | |||
HOW TO OPEN A WRITE PROTECTED FILE (USB) | Excel Discussion (Misc queries) | |||
I have a read only xl file, I need it to be read and write | Excel Discussion (Misc queries) | |||
read only file-need to write | Excel Discussion (Misc queries) | |||
How can a file be converted from Read-Only to Read/Write | Excel Discussion (Misc queries) |