LWThompson
November 3rd, 1999, 10:44 PM
Does anyone have any code that will open a text file for editing. Specifically, I wish to open 4 text files and erase the first line of text and then save each of the files under a new file name.
Any help would be appreciated.
thank you.
Peter Postlbauer
November 3rd, 1999, 11:56 PM
Hi Larry
try to solve your problem with the notepad:
First you need to declare some functions (maybe, you'll need not all of them, just try it) and constants
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetFileAttributes Lib "kernel32.dll" _
Alias "GetFileAttributesA" _
(ByVal lpFileName As String) As Long
Private Const STILL_ACTIVE = &H103
Private Const PROCESS_QUERY_INFORMATION = &H400
I had to modify a ini-file, so I wrote the function ModifyIni:
call the function:
ModifyIni "NOTEPAD PKSWFRV.INI", vbNormalFocus
Public Function ModifyIni(ByVal JobToDo As String, Optional ExecMode) As Long
Dim ProcessID As Long
Dim hProcess As Long
Dim nRet As Long
Const fdwAccess = PROCESS_QUERY_INFORMATION
On Error Resume Next
ProcessID = Shell(JobToDo, CLng(ExecMode))
If Err Then
ModifyIni vbObjectError + Err.Number
Exit Function
End If
On Error GoTo 0
hProcess = OpenProcess(fdwAccess, False, ProcessID)
Do
GetExitCodeProcess hProcess, nRet
DoEvents
Sleep 100
Loop While nRet = STILL_ACTIVE
Call CloseHandle(hProcess)
ModifyIni = nRet
End Function
regards,Peter