So I asked this the other night and the Binary function supplied is not the same as opening the file in notepad. I have code that checks the modified date of the file and opens in wordpad.exe Then it saves the file. There are approximately 10 files and 10macros that I'm calling and some of the files take a couple of minutes to open. So all of the files are opening in Notepad at once and my sendkeys command is not always working.
The file must be opened and saved in notepad to remove some erroneous data that exists.
Sub FileLastMod()
Dim oFS As Object
Dim strFilename As String
Dim n As Integer
Dim firstdate As Date
Dim seconddate As Date
'Put filename here
strFilename = "g:\Jim.txt"
Set oFS = CreateObject("Scripting.FileSystemObject")
firstdate = Date
seconddate = oFS.GetFile(strFilename).Datelastmodified
n = DateDiff("d", firstdate, seconddate)
'Begin first leg of code here
On Error Resume Next
If n = 0 Then
Shell "notepad.exe g:\Jim.txt", vbNormalFocus
SendKeys "^s", (wait)
DoEvents
SendKeys "%fx"
If n = 0 Then Exit Sub
End If
'Begin 2nd leg of code here - checks to see if it's Sunday or Monday
If Weekday(Date) = 1 Or Weekday(Date) = 2 Then
Shell "notepad.exe g:\Jim.txt", vbNormalFocus
SendKeys "^s", (wait)
DoEvents
SendKeys "%fx"
If n = 0 Then Exit Sub
End If
'Begin 3rd leg of code here - waits for files to be updated
Do
strFilename = "g:\Jim.txt"
Set oFS = CreateObject("Scripting.FileSystemObject")
firstdate = Date
seconddate = oFS.GetFile(strFilename).Datelastmodified
n = DateDiff("d", firstdate, seconddate)
Loop Until n = 0
If n = 0 Then
Shell "notepad.exe g:\Jim.txt", vbNormalFocus
SendKeys "^s", (wait)
DoEvents
SendKeys "%fx"
If n = 0 Then Exit Sub
End If
End Sub
Bookmarks