'vba read only open sample
Option Explicit
Private Const READONLY = 1&
Sub CATMain()
Dim path As String
path = "C:\temp\Part1.CATPart"
If Not isExist(path) Then
Dim msg As String
msg = "File not found" & vbCrLf & path
MsgBox msg
Exit Sub
End If
Dim backupAttr As Long
backupAttr = getAttributes(path)
If Not (backupAttr And READONLY = READONLY) Then
Call setAttributes(path, READONLY)
End If
Call CATIA.Documents.Open(path)
If Not (backupAttr And READONLY = READONLY) Then
Call setAttributes(path, backupAttr)
End If
End Sub
Private Sub setAttributes( _
ByVal path As String, _
ByVal Value As Long)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.GetFile(path).Attributes = Value
End Sub
Private Function getAttributes( _
ByVal path As String) _
As Long
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
getAttributes = fso.GetFile(path).Attributes
End Function
Private Function isExist( _
ByVal path As String) _
As Boolean
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
isExist = fso.FileExists(path)
End Function