Need help adding file select

Ok guys,

First off thank you all for your help so far.  Here is what I have:


Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim path As String
Dim path2 As String
Dim path3 As String
Dim file As String
Dim file2 As String
Dim lWarnings As Long, lErrors As Long
Dim sFileName As String
Dim NewFileName As String
Dim NewFileName2 As String
Dim DrawingTemplate As String


Sub main()


    path = GetFolder("Select a folder which has drawings that you want to convert to DWG & PDF")
    DrawingTemplate = InputBox("Enter the name of the drawing template")
    DrawingTemplate = DrawingTemplate + ".SLDDRW"
    NewFileName = InputBox("Enter the name of the new file:")
    Set swApp = Application.SldWorks
  
If (Right(path, 1) <> "\") Then
     path = path + "\"
End If
    file = Dir(path + DrawingTemplate, vbNormal)
    While file <> ""
        If (Right(UCase(file), 7) = ".SLDDRW") Then
            Set Part = swApp.OpenDoc6(path + file, 3, 0, "", longstatus, longwarnings)
            Part.ViewZoomtofit2
           
            path2 = GetFolder("Select a folder where the DWG and PDF will be saved")
            If (Right(path2, 1) <> "\") Then
                path2 = path2 + "\"
            End If
            path3 = path2
            path2 = path2 + NewFileName
            file2 = Dir(path2, vbNormal)
            longstatus = Part.SaveAs(file2 + path2 + ".DWG")
           
           
            NewFileName2 = NewFileName + ".PDF"
           
            path3 = path3 + NewFileName2
               
  ' I have added this for PDF creation
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    If swModel Is Nothing Then
        MsgBox "No current document", vbCritical
        End
    End If
    If swModel.GetType <> swDocDRAWING Then
        MsgBox "This Macro only works on Drawings", vbCritical
        End
    End If
    Set swModelDocExt = swModel.Extension
    Set swExportData = swApp.GetExportFileData(swExportPdfData)
    FileName = swModel.GetPathName
    If FileName = "" Then
        MsgBox "Please save the file first and try again", vbCritical
        End
    End If
    FileName = Strings.Left(FileName, Len(FileName) - 6) & "PDF"
   
    boolstatus = swExportData.SetSheets(swExportData_ExportAllSheets, 1)
   
    boolstatus = swModelDocExt.SaveAs(file2 + path3, 0, 0, swExportData, lErrors, lWarnings)
   
    If boolstatus Then
        MsgBox "Save as PDF & DWG successful" & vbNewLine
    Else
        MsgBox "Save as PDF & DWG failed, Error code:" & lErrors
    End If
   
    swApp.CloseDoc (swModel.GetPathName)
   
    Set swApp = Nothing
    Set swModel = Nothing
    Set swModelDocExt = Nothing
    Set swExportData = Nothing
           
           
       End If
       
    file = ""
       
    Wend
End Sub

And here is the Module

Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Public Const BIF_RETURNONLYFSDIRS = &H1
Public Const BIF_DONTGOBELOWDOMAIN = &H2
Public Const BIF_STATUSTEXT = &H4
Public Const BIF_RETURNFSANCESTORS = &H8
Public Const BIF_BROWSEFORCOMPUTER = &H1000
Public Const BIF_BROWSEFORPRINTER = &H2000
Public Const BIF_NEWDIALOGSTYLE = &H40
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Public Function GetFolder(ByVal sTitle As String) As String

Dim bInf As BROWSEINFO
Dim retval As Long
Dim PathID As Long
Dim RetPath As String
Dim Offset As Integer

bInf.lpszTitle = sTitle
bInf.ulFlags = BIF_NEWDIALOGSTYLE
PathID = SHBrowseForFolder(bInf)
RetPath = Space\$(512)

retval = SHGetPathFromIDList(ByVal PathID, ByVal RetPath)

If retval Then

Offset = InStr(RetPath, Chr\$(0))
GetFolder = Left\$(RetPath, Offset - 1)

End If

End Function

For the DrawingTemplate I would like to add a browse to file and select function instead of manually entering the name of the drawing template.  Can anyone help me out????

Thank you,

Nick


SolidworksApi macros