call a text function

jwhite

New Member
Joined
Sep 23, 2002
Messages
8
Hi, I have already asked but didn't get a response, I'll try again....
I have a date in a text file (rvf.txt) and want my macro to go and check if that date is less than or greater than todays date....
Can this be done in VB please?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
On 2002-09-24 23:02, jwhite wrote:
Hi, I have already asked but didn't get a response, I'll try again....
I have a date in a text file (rvf.txt) and want my macro to go and check if that date is less than or greater than todays date....
Can this be done in VB please?

Can you explain what you mean by 'in a txt file'?
Do you mean in the file name or in the file, if you mean in the file where is it?
 
Upvote 0
Anno...it was a little longer than 20 minutes thank you! And I thought the original question may have been unclear and wanted to restate it, don't jump all over me buddy!
The text file is on the C: drive in a seperate folder and simply contains a date.
rgds
Jeff
 
Upvote 0
On 2002-09-24 23:46, jwhite wrote:
Anno...it was a little longer than 20 minutes thank you! And I thought the original question may have been unclear and wanted to restate it, don't jump all over me buddy!
The text file is on the C: drive in a seperate folder and simply contains a date.
rgds
Jeff

Jeff...hey he is a fellow Aussie :)
You didn't specify the date format...
Here is one way ...Try this routine.

<pre/>
Sub ReadFromFile()
Dim Fs As FileSystemObject
Dim Ts As TextStream
Dim sVar
Dim TodaysDate
Dim Result As String

'// Change this constant to your Full path name
Const sFile As String = "C:AATextone.txt"
Const sLess As String = " Less then "
Const sGreater As String = " Greater then "

TodaysDate = Date
Set Fs = CreateObject("Scripting.FileSystemObject")
Set Ts = Fs.OpenTextFile(sFile)

With Ts
sVar = .ReadAll
.Close
End With

sVar = CVDate(sVar)
Result = IIf(TodaysDate < sVar, sLess, sGreater)

MsgBox "Text date:= " & sVar & vbCr & _
"Todays Date:= " & TodaysDate & vbCr & _
"Todays date is" & Result & "TextFile date!"

End Sub
</pre>
 
Upvote 0
Thanks Ivan, I'll give it a try and let you know.
Anno might be an Aussie but he's an angry little bugger...not like an Aussie at all really.
Thanks again.
Jeff
 
Upvote 0
Ivan, the message seems to say that todays date is less than the textfile date regardless of the tex file date?
Thanks
Jeff
 
Upvote 0
On 2002-09-25 14:35, jwhite wrote:
Ivan, the message seems to say that todays date is less than the textfile date regardless of the tex file date?
Thanks
Jeff

How is the text file date formated ie
does the date appear as 12/09/2002 or something else eg 12th Sept 2002 ??
 
Upvote 0
Ivan...the date was 12.09.02 and I've tried 12/09/02, 12/09/2002 without success.
Not that it matters, but I also had to remove the first 2 lines of code before it would work without errors. But now it works, except for the "greater or less than".
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top