vbams-accesshidden-filesfile-properties

Is there an argument for copyfile that will change the hidden property?


I have a database that writes data into a copied excel template. The template is hidden to keep the end user from tampering with it, however the final result is also hidden. Is there a way to change the hidden property when saving the new file?

Currently, the db copies the template and renames it.

fso.CopyFile "C:\Upload\Rebate_Upload_Files\Standard Form (Template) 
protected.xlsx", "C:\Upload\Rebate_Upload_Files\Rebate Contract " & 
Contract_Number & " " & Date$ & ".xlsx"

After that, it transfers the appropriate table and saves the file.

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, 
"export_table", "C:\Upload\Rebate_Upload_Files\Rebate Contract " & 
Contract_Number & " " & Date$ & ".xlsx", False, "A12:L65000"

The process works fine, except that the final file is also hidden and I'd like it to be a normal file.

Thanks


Solution

  • Not for CopyFile-which is a FileSystemObject method, but there is one for a File object. We'll just update it after the copy is complete.

    For simplicity i've replaced your file output path to a string variable.

    originalFileName = "yourStartingFile"
    copyFileName = "yourCopiedFile"
    
    set fso.CopyFile OriginalFileName, CopyFileName
     --after copying, get file that was copied
     --set attributes value of file to 0. 0 = Normal, 2 = Hidden
    f = fso.GetFile(copyFileName)
    f.attributes = 0
    

    More reading for additional details.

    https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/file-object

    https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/attributes-property