< Back

Document Subject: Make sure directory exists
Hint Short Cut: Add this to your code & documentation to help you find this page.
http://#DirExists or http://A555F9/nn.nsf/ByAlias/DirExists

Quick bit of code to make sure a directoy exists before detaching a file, as the directory will not be created automatically.




 

If Dir$("c:\temp",16)="" Then Mkdir "c:\temp"

 

If there are subdirectories then you have to make check each level eg:

If Dir$("c:\temp",16)="" Then Mkdir "c:\temp"

If Dir$("c:\temp\sub",16)="" Then Mkdir "c:\temp\sub"

You cannot make all directories in one go.

 

Then you can detach the file eg:

Dim htmlrt As Variant  
 Set htmlrt = uidoc.document.GetFirstItem("Htmlfile")
 If htmlrt.type=richtext Then
  Forall o In htmlrt.EmbeddedObjects
   If ( o.Type = EMBED_ATTACHMENT ) Then
    If Dir$("c:\temp",16)="" Then Mkdir "c:\temp"
    Call o.ExtractFile( "c:\tempHTML\" & o.Source )    

      'do stuff then delete file

      kill "c:\tempHTML\" & o.Source
   End If
  End Forall      
 End If