Message 1 of 5
Opening .dwf files from Excel VBA

Not applicable
08-08-2002
03:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have an excel spreadsheet with .dwf drawing file names and verbal descriptions I'm developing an application to open a selected drawing from this spreadsheet (using VBA). I get the error "File name or class name not found during Automation operation" when attempting to run the macro. The code is shown below.
Option Explicit
Public Const TopR As Long = 4 'Top row of data
Public Const FType As String = ".dwf"
Public Const Col_SD As Long = 1 'Subdirectory column
Public Const Col_File As Long = 2 'File Name column
Public DWFDoc, DWFApp As Application
Public RowNum As Long, LastR As Long
Public M_Dir As String, S_Dir As String, FileNm As String, PathNm As String
Sub DWF_Open()
'Routine to open a DWF file from an index. Index must
' be in a format created by file CAD_NDX.xls. In the
' index, select the cell containing the file name of
' the drawing to be opened. Click "Open" button.
RowNum = Selection.Row
LastR = ActiveSheet.UsedRange.Rows.Count
If RowNum < TopR Or RowNum > LastR Then End 'Stop for invalid entry
M_Dir = Trim(Range("IndexPath").Text) 'Get Main directory
If Right(M_Dir, 1) = "\" Then M_Dir = Left(M_Dir, Len(M_Dir) - 1) 'Trim backslash
S_Dir = Trim(Cells(RowNum, Col_SD).Text) 'Get Sub directory
If Right(S_Dir, 1) = "\" Then S_Dir = Left(S_Dir, Len(S_Dir) - 1) 'Trim backslashes
If Left(S_Dir, 1) = "\" Then S_Dir = Right(S_Dir, Len(S_Dir) - 1) 'in sub directory
FileNm = Trim(Cells(RowNum, Col_File).Text) 'Get File Name
PathNm = M_Dir + "\"
If S_Dir <> "" Then PathNm = PathNm + S_Dir + "\" 'Add Sub Dir if not blank
FileNm = PathNm + FileNm + FType 'Get completed filename
Set DWFDoc = GetObject(FileNm) 'Open Drawing
Set DWFApp = DWFDoc.Application
AppActivate (DWFApp.Caption) 'Show AutoCAD window
End Sub
Option Explicit
Public Const TopR As Long = 4 'Top row of data
Public Const FType As String = ".dwf"
Public Const Col_SD As Long = 1 'Subdirectory column
Public Const Col_File As Long = 2 'File Name column
Public DWFDoc, DWFApp As Application
Public RowNum As Long, LastR As Long
Public M_Dir As String, S_Dir As String, FileNm As String, PathNm As String
Sub DWF_Open()
'Routine to open a DWF file from an index. Index must
' be in a format created by file CAD_NDX.xls. In the
' index, select the cell containing the file name of
' the drawing to be opened. Click "Open" button.
RowNum = Selection.Row
LastR = ActiveSheet.UsedRange.Rows.Count
If RowNum < TopR Or RowNum > LastR Then End 'Stop for invalid entry
M_Dir = Trim(Range("IndexPath").Text) 'Get Main directory
If Right(M_Dir, 1) = "\" Then M_Dir = Left(M_Dir, Len(M_Dir) - 1) 'Trim backslash
S_Dir = Trim(Cells(RowNum, Col_SD).Text) 'Get Sub directory
If Right(S_Dir, 1) = "\" Then S_Dir = Left(S_Dir, Len(S_Dir) - 1) 'Trim backslashes
If Left(S_Dir, 1) = "\" Then S_Dir = Right(S_Dir, Len(S_Dir) - 1) 'in sub directory
FileNm = Trim(Cells(RowNum, Col_File).Text) 'Get File Name
PathNm = M_Dir + "\"
If S_Dir <> "" Then PathNm = PathNm + S_Dir + "\" 'Add Sub Dir if not blank
FileNm = PathNm + FileNm + FType 'Get completed filename
Set DWFDoc = GetObject(FileNm) 'Open Drawing
Set DWFApp = DWFDoc.Application
AppActivate (DWFApp.Caption) 'Show AutoCAD window
End Sub