从文本框

时间:2018-01-24 20:20:06

标签: excel vba excel-vba csv userform

我正在开发一个用户表单,如下所示 enter image description here

浏览按钮中的代码是

Private Sub Browse_Click()

    Dim fName As String
        fName = Application.GetOpenFilename("CSV File (*.csv), *.csv", , "Import .CSV File", , False)

    If Not fName = "False" Then
        TextBox1.Value = fName
    End If

End Sub

下一步是选择其中一些选项,其背后的代码是

Private Sub Start_Click()

    Dim Actsheet As String
    Dim wkbCrntWorkBook As Workbook
    Dim wkbSourceBook As Workbook
    Dim rngSourceRange As Range
    Dim rngDestination As Range
    Set wkbCrntWorkBook = ActiveWorkbook
    Set rngDestination = wkbCrntWorkBook.ActiveSheet.Range("A1:A1")


    If myBeforeImprovements = True Then
        Actsheet = "Before "
    ElseIf AfterImprovements = True Then
        Actsheet = "After "
    Else
        MsgBox ("Select Type of Analysis")
        Exit Sub
    End If


    If Westbound = True Then
        Actsheet = Actsheet & "WB"
    ElseIf Northbound = True Then
        Actsheet = Actsheet & "NB"
    ElseIf Eastbound = True Then
        Actsheet = Actsheet & "EB"
    ElseIf Southbound = True Then
        Actsheet = Actsheet & "SB"
    Else
        MsgBox ("Select Traffic Bound")
        Exit Sub
    End If

我的问题是我无法将CSV文件写入其写入表格 在EB之前 在WB之前 在NB之前 在SB之前 EB之后 WB之后 NB之后 SB之后

以下代码可能会引用所选的CSV文件,但它会给我一个错误

Workbooks.OpenText Filename:=TextBox1.Text + "," + ComboBox1.Value + ".txt", _
DataType:=xlDelimited, Tab:=True

1 个答案:

答案 0 :(得分:1)

+替换为&,希望它能更好地发挥作用。连接运算符是&在VBA