Opening .dwf files from Excel VBA

Opening .dwf files from Excel VBA

Anonymous
Not applicable
1,151 Views
4 Replies
Message 1 of 5

Opening .dwf files from Excel VBA

Anonymous
Not applicable
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
0 Likes
1,152 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
You cant execute the .dwf file in the same way you executed the dwg file.
Open a command window, and go to a directory where you have a dwg file and
type just the name of the dwg file at the command line. It opens up autocad.
Now, try that with a DWF, and it wont work. You'll need to start your
prefered dwf viewer and then tell it to open your DWF. Note that the command
line stuff does not work in win9x IIRC.

-Anthony


------------------
"jimmilam" wrote in message
news:f100a8f.-1@WebX.maYIadrTaRb...

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
0 Likes
Message 3 of 5

Anonymous
Not applicable
Anthony,
Thanks. I pulled up a command prompt, and sure enough, .dwg's open and .dwf's don't. I don't know how to use a VBA macro to start my dwf viewer (internet explorer) and have it open a dwf file. Any ideas?
Thanks again,
Jim
0 Likes
Message 4 of 5

Anonymous
Not applicable
Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")
oIE.navigate2
oIE.Visible = True

-A
----------------------
"jimmilam" wrote in message
news:f100a8f.1@WebX.maYIadrTaRb...
Anthony,
Thanks. I pulled up a command prompt, and sure enough, .dwg's open and
.dwf's don't. I don't know how to use a VBA macro to start my dwf viewer
(internet explorer) and have it open a dwf file. Any ideas?
Thanks again,
Jim
0 Likes
Message 5 of 5

Anonymous
Not applicable
Thanks Anthony. I'm about to go on vacation, but will try it out when I get back.
Jim
0 Likes