【SolidWorks宏】读取文件的第一行数据

Rem "读取文件的第一行数据"
Public Function ReadFirstLineDataFromFile(fileName) As String
    '声明
    Dim filePath As String
    Dim fs As Object
    Dim otf As Object
    
    '执行过程
    filePath = fileName
    Set fs = CreateObject("Scripting.FileSystemObject")

    If fs.FileExists(filePath) = True Then
        Set otf = fs.OpenTextFile(filePath, 1, True)
        ReadFirstLineDataFromFile = otf.ReadLine()
        otf.Close
     Else
         MsgBox "文件""" & fileName & """不存在"
    End If
End Function

猜你喜欢

转载自blog.csdn.net/chenlu5201314/article/details/80287440