KeithZ said:
Hi-
I need to hide a file that is refreshed every day through a macro.
Could code be put in the macro so that after the file is added it is
automatically made hidden?
thanks a bunch
A file? Or a table. If you really mean a file, then you could call a
function like this:
'----- start of code -----
Sub HideUnhideFile(pstrFilespec As String, pblnShowFile As Boolean)
'*** Assumes Windows Scripting is enabled ***
Dim fs As Object
Dim f As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(pstrFilespec)
If pblnShowFile Then
f.Attributes = f.Attributes And (Not vbHidden)
Else
f.Attributes = f.Attributes Or vbHidden
End If
End Sub
'----- end of code -----
With that function defined in a standard module, you could call it to
hide, say, file "C:\Temp\foo.txt" like this:
HideUnhideFile "C:\Temp\foo.txt", False
If you later wanted to unhide the file, you'd say this:
HideUnhideFile "C:\Temp\foo.txt", True
Note that the function as written includes no error-handling. That's
left up to you to implement.