检查是否打开了图形(文件)
有可能用VBA代码找到AutoCAD是否有打开的文件,或者根本没有打开的文件吗?**** Hidden Message *****
'Sample Code: Microsoft Visual Basic version of IsFileAlreadyOpen
'----------------------------------------------------------------
' Declaration for APIs used by our function...
Private Declare Function lopen Lib "kernel32" Alias "_lopen" (ByVal
lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal
hFile As Long) As Long
Function IsFileAlreadyOpen(Filename As String) As Boolean
Dim hFile As Long
Dim lastErr As Long
' Initialize file handle and error variable.
hFile = -1
lastErr = 0
' Open for for read and exclusive sharing.
hFile = lopen(Filename, &H10)
' If we couldn't open the file, get the last error.
If hFile = -1 Then
lastErr = Err.LastDllError
' Make sure we close the file on success.
Else
lclose (hFile)
End If
' Check for sharing violation error.
If (hFile = -1) And (lastErr = 32) Then
IsFileAlreadyOpen = True
Else
IsFileAlreadyOpen = False
End If
End Function
好,我试试看! 您好,
现在无法尝试使用它来提供完美的代码
但我认为它是这样的:
msgbox application.documents。计数
希望它能工作
/r
ps
我希望我已经理解了你的问题。。。 检查这个
' Declaration for APIs used by our function...
Private Declare Function lopen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long
Sub test()
IsFileAlreadyOpen ("P:\Autocad\Library\Test.dwg")
End Sub
Function IsFileAlreadyOpen(Filename As String) As Boolean
Dim hFile As Long
Dim lastErr As Long
' Initialize file handle and error variable.
hFile = -1
lastErr = 0
' Open for for read and exclusive sharing.
hFile = lopen(Filename, &H10)
' If we couldn't open the file, get the last error.
If hFile = -1 Then
lastErr = Err.LastDllError
' Make sure we close the file on success.
Else
lclose (hFile)
End If
' Check for sharing violation error.
If (hFile = -1) And (lastErr = 32) Then
IsFileAlreadyOpen = True
MsgBox Filename & " Is Already Open"
Else
IsFileAlreadyOpen = False
ThisDrawing.Application.Documents.Open Filename
End If
End Function
非常感谢Ricky_76,
代码对我来说已经足够了!
页:
[1]