Hiding an Excel file using VBA

S

Steve Jones

Hi,
I am using Excel 2003.

Is it possible for me to so save an Excel file within VBA so that it is not
visible in the folder it is saved in?
This is an extract of the code I have which currently saves the file:

ActiveWorkbook.SaveAs Filename:="\purchases\ " & name & ".xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="xxx", _
ReadOnlyRecommended:=False, CreateBackup:=False

I know once the file has been saved I can set the file properties to hidden
which works but didn't know whether or not it was possible within VBA.

Thanks very much
 
J

Jim Cone

Try the following with the correct file path...
'---
Sub OutOfSight()
Dim strPath As String
strPath = "C:\SomeFolder\AnotherFolder\SomeFileName.xls"
Call TheShadowKnows(strPath)
End Sub
'---
Function TheShadowKnows(ByRef FileLocation As String) As Boolean
Dim fso As Object
Dim f As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(FileLocation)
If Not f.Attributes And 2 Then f.Attributes = f.Attributes + 2
Set f = Nothing
Set fso = Nothing
End Function
'---
More on the FileSystemObject here...
http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
'---
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware
(List Files XL add-in: finds and lists files/folders with hyperlinks)





"Steve Jones"
<[email protected]>
wrote in message
news:[email protected]...
 

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