Hiding a file with VBA

G

Guest

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
keithz
 
D

Dave Patrick

Try (all on one line);
Shell "Attrib +h ""E:\Documents and Settings\Administrator\My
Documents\myfile.txt""", 0


--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| 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
| keithz
 
D

Dirk Goldgar

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top