Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default External File Validation?

I received some assistance on putting this macro together and tweaked it
until it did what I wanted. However, I had to change the name of the input
file and realized that if the file name the script searches for is not valid,
it will kick out an error.

I want to be able to include a statement that says something like, IF
FILENAME.xls IS MISSING THEN "FILE MISSING" or something like that.

How would I modify this code?

Sub SourceDateTime_VENDOR_A()
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("FILEPATH_GOES_HERE\FileName.txt")
Application.Goto Reference:="R18C1"
ActiveCell.FormulaR1C1 = (f.datelastmodified)
Application.Goto Reference:="R18C7"
ActiveCell.FormulaR1C1 = "=IF(RC[-6](TODAY()+0.99999),""Future
Data?"",(IF(RC[-6]<TODAY(),""Old Data"",""Validated"")))"
End Sub

Thanks for your help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default External File Validation?

The Dir function will return an empty string ("") if a specified filename
does not exist.

strtFilename = "FILEPATH_GOES_HERE\FileName.txt"
If Len(Dir(strFilename))=0 Then
'File doesn't exist. Exit? prompt User?
Msgbox "Cancelling: " & strFilename & " does not exist."
Exit Sub
End If

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(strFileName)
'........etc

HTH,

"RayportingMonkey" wrote in
message ...
I received some assistance on putting this macro together and tweaked it
until it did what I wanted. However, I had to change the name of the input
file and realized that if the file name the script searches for is not
valid,
it will kick out an error.

I want to be able to include a statement that says something like, IF
FILENAME.xls IS MISSING THEN "FILE MISSING" or something like that.

How would I modify this code?

Sub SourceDateTime_VENDOR_A()
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("FILEPATH_GOES_HERE\FileName.txt")
Application.Goto Reference:="R18C1"
ActiveCell.FormulaR1C1 = (f.datelastmodified)
Application.Goto Reference:="R18C7"
ActiveCell.FormulaR1C1 = "=IF(RC[-6](TODAY()+0.99999),""Future
Data?"",(IF(RC[-6]<TODAY(),""Old Data"",""Validated"")))"
End Sub

Thanks for your help!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i reference an external workbook for data validation? Dex Excel Discussion (Misc queries) 2 October 27th 09 06:13 PM
Validation with External Data Names Chakey Excel Worksheet Functions 0 June 25th 08 06:25 PM
external refs and dropdown validation NJS Excel Worksheet Functions 3 January 28th 08 08:29 PM
external validation BorisS Excel Discussion (Misc queries) 0 February 21st 07 07:57 PM
Referring to external workbook in Data Validation aposatsk Excel Discussion (Misc queries) 2 August 21st 06 04:24 PM


All times are GMT +1. The time now is 01:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"