Hi dear,
I am still learning about vba. I have a code to create copy/duplicate file to other directory, like this:
But, now I want to add or change the code so that the file copy on the server (\\ 192.168.0.6 \ Production) becomes a read only file so it can be opened but it cannot be modified by others. Can you help me? Thank you (Note: Sorry for my bad English)
I am still learning about vba. I have a code to create copy/duplicate file to other directory, like this:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim wb As Workbook: Set wb = ThisWorkbook
Dim FSO As Object
Dim strTargetPath As String
Dim strFileName As String
Dim strFilestrFileExtensionension As String
Dim strFolderName As String
Application.EnableEvents = False
strTargetPath = "\\192.168.0.6\Production"
strFileName = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".") - 1))
strFileExtension = Right(ThisWorkbook.Name, Len(ThisWorkbook.Name) - InStrRev(ThisWorkbook.Name, "."))
strFolderName = strFileName
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(strTargetPath) Then
If Not FSO.FolderExists(strTargetPath & "/" & strFolderName) Then
FSO.CreateFolder (strTargetPath & "/" & strFolderName)
End If
wb.SaveCopyAs strTargetPath & "\" & strFolderName & "\" & strFileName & "." & strFileExtension
Else
MsgBox "ERROR: Source File does not exist or is not accessible."
End If
Application.EnableEvents = True
End Sub