微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将csv文件导入到excel和列A导入为文本

如何解决如何将csv文件导入到excel和列A导入为文本

在该网站的出色会员的帮助下,我很好地拥有以下工作代码

Private Sub Imprtstckbtn_Click()
Dim vR(),vDB
Dim WbCSV As Workbook,Wb As Workbook
Dim Ws As Worksheet
Dim i As Long,n As Integer
Dim vFile As Variant


Application.ScreenUpdating = False
Set Wb = ThisWorkbook
Set Ws = Wb.Sheets(2)

'Select a text file through the file dialog.
'Get the path and file name of the selected file to the variable.
vFile = Application.GetopenFilename("ExcelFile *.txt,*.txt;*.csv",_
   Title:="Select CSV file",MultiSelect:=False)
   
'If you don't select file,exit sub.
If TypeName(vFile) = "Boolean" Then Exit Sub

'The selected text file is imported into an Excel file. format:2 is csv,format:1 is tab
Set WbCSV = Workbooks.Open(Filename:=vFile,Format:=2)

'Bring all the contents of the sheet into an array.
With WbCSV.Sheets(1)
    vDB = .UsedRange
    For i = 1 To UBound(vDB,1)
        'AA column = 27,AP column = 42
        If vDB(i,27) = "SO0000" And vDB(i,42) = 0 Then
        
        ElseIf vDB(i,27) = "SR0000" And vDB(i,27) = "WG0000" And vDB(i,42) = 0 Then
        
        Else
            'Get the contents corresponding to the dynamic array. Bring the matrix to the inverted state.
            n = n + 1
            ReDim Preserve vR(1 To 5,1 To n)
            vR(1,n) = vDB(i,1)
            vR(2,2)
            vR(3,3)
            vR(4,27)
            vR(5,42)
        End If
    Next i
End With
'Colse the text file
WbCSV.Close (0)
    
'The dynamic array is recorded in sheet2.Bring the row to the inverted state.
With Ws
    .UsedRange.Clear
    .Range("a1").Resize(n,5).Value = WorksheetFunction.Transpose(vR)
End With
Worksheets("Sheet2").Columns("A:E").AutoFit
Application.ScreenUpdating = True

End Sub

我现在唯一的问题是正在导入的工作表的A列是股票代码,问题是当我导入它时,删除了前导零或excel将长数字赋予科学价值。我需要将A列导入为文本,以确保excel不会将其归类为数字。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。