'一番初めに読み込むプロシージャ Sub main() 'お決まりの文句 Dim swApp As Object Dim Part As Object Dim boolstatus As Boolean Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Dim myView As Object Set myView = Part.ActiveDrawingView If myView Is Nothing Then MsgBox "ビューをアクティブにして" & vbNewLine & "やり直してください。" Exit Sub End If 'ユーザーフォームの作成 Dim uf1 As New UserForm1 uf1.Show myView.FocusLocked = True Dim myNote As Object Dim myAnnotation As Object '注記の挿入 Set myNote = Part.InsertNote("P/C 2") Set Annotation = myNote.GetAnnotation() boolstatus = Annotation.SetPosition(0.2, 0.2, 0) Part.ClearSelection2 True myView.FocusLocked = False '念のため再構築 Part.WindowRedraw End Sub
'選択したファイル名 Dim flName As String 'ファイルの選択 Private Sub CommandButton2_Click() Dim Filter As String Dim fileConfig As String Dim fileDispName As String Dim fileOptions As Long Set swApp = Application.SldWorks ' This following string has three filters associated with it; note the use '次の文字列には3つのフィルタが関連付けられています。 使用に注意する ' of the | character between filters 'フィルター間の文字 Filter = "CSVファイル (*.csv; *.CSV)|*.csv;*.CSV" flName = swApp.GetOpenFileName("File to Attach", "", Filter, fileOptions, fileConfig, fileDispName) ' In the dialog, click the down-arrow associated with Files to Type to see the filters ' ' dialogFiles of Type down arrow key ' If flName = vbNullString Then MsgBox "ファイルが選択されていません。" Else 'ファイルが選択されている場合はラベルに表示 Label4.Caption = flName End If End Sub Private Sub CommandButton1_Click() Dim str1 As String Dim txt1 As String Dim num1 As Integer txt1 = TextBox1.Text num1 = Len(txt1) 'テキストボックスが空欄の場合は、 '直ちに終了する If num1 = 0 Then MsgBox "テキストボックスが空欄になっています、" & vbNewLine & "部品名をコピーして、" & vbNewLine & "やり直してください。" End End If 'if分で終了しない場合はファイル処理のクラスを作成する Dim fl As New fleget '//下記の部分で構文エラーになる fl.readfl(flName,txt1) Unload Me End Sub
Dim p_count As String Public Sub readfl(fnm As String, pnm As String) Dim fso As New Scripting.FileSystemObject Dim csvFile As Object Dim csvData As String Dim splitcsvData As Variant Dim i As Integer Dim j As Integer Set csvFile = fso.OpenTextFile(fnm, 1) i = 1 Do While csvFile.AtEndOfStream = False csvData = csvFile.ReadLine splitcsvData = Split(csvData, ",") j = UBound(splitcsvData) + 1 If pnm = splitcsvData(2) Then MsgBox splitcsvData(2) End If i = i + 1 Loop csvFile.Close Set csvFile = Nothing Set fso = Nothing End Sub