| 
    
     |  | 善く見ると、OpenTextFileの引数の関係ではない様です ForWriting、ForAppendingは参照設定で実行する場合、
 定数宣言は要らないみたいですね?(参照設定で使った事が無いのでゴメン)
 多分この不備は、Dirの使い方が悪い様です
 
 結果ファイル1 = Dir("c:\documents and settings\maki\デスクトップ\" _
 & 製番1 & ActiveSheet.Name, Attributes:=vbNormal)
 
 で、ファイルの存在確認を行って居る様ですが、此れではFolderの存在確認で
 結果ファイル1 に "結果.txt"は、返りませんので常に、Else節が実行されます
 
 Option Explicit
 
 Public Sub Test()
 
 Const clngForWriting As Long = 2
 Const clngForAppending As Long = 8
 
 '?不明な変数若しくはリテラル
 Dim 製番1 As String
 Dim 番号 As String
 Dim 材料名 As String
 Dim サイズ As String
 Dim 長さ As String
 Dim 数量 As String
 
 Dim OldF As String
 Dim NewF As String
 Dim lngIOmode As Long
 Dim strOutPath As String
 Dim strFileName As String
 
 '○結果をテキストファイルに書き込み
 Dim myfso As New FileSystemObject
 Dim mytext As TextStream
 
 strOutPath = "c:\documents and settings\maki\デスクトップ\" _
 & 製番1 & ActiveSheet.Name
 strFileName = "結果.txt"
 
 With myfso
 OldF = .GetFileName("c:\加工図\" & Selection.Value & ".dwg")
 NewF = .GetFileName(strOutPath & "\" & 番号 & 材料名 & "×" _
 & サイズ & "×" & 長さ & "-" & 数量 & "s.dwg")
 'ファイルの存在確認
 If .FileExists(strOutPath & "\" & strFileName) Then
 lngIOmode = clngForAppending
 Else
 lngIOmode = clngForWriting
 End If
 Set mytext = .OpenTextFile(strOutPath & "\" & strFileName, lngIOmode)
 End With
 
 With mytext
 .Write OldF & "→" & NewF
 .Close
 End With
 
 Set mytext = Nothing
 Set myfso = Nothing
 
 End Sub
 
 |  |