从组合框将 CSV 加载到 select 个工作表
Load CSV to select sheets from combobox
我有两个用户窗体。带有月份名称的组合框和用于将 CSV 文件加载到从组合框列表中选择的月份的按钮。当我上传我的 CSV 文件时,总是在 Sheet(12).
中打印数据
我想创建用户窗体以将 CSV 文件上传到选定的 Sheet 表单组合框列表。
目前 excel 文件中有 12 张带有月份名称的表格。也许我需要将我的工作表名称与这个 .AddItem 结合起来?
Private Sub Userform_Initialize()
Dim month(12) As String
Dim i As Integer
month(1) = "Styczeń"
month(2) = "Luty"
month(3) = "Marzec"
month(4) = "Kwiecień"
month(5) = "Maj"
month(6) = "Czerwiec"
month(7) = "Lipiec"
month(8) = "Sierpień"
month(9) = "Wrzesień"
month(10) = "Październik"
month(11) = "Listopad"
month(12) = "Grudzień"
Dim ws As Worksheet
For i = 1 To 12
UseForm_START.Dane_miesiac.AddItem month(i)
Next i
End Sub
Private Sub CommandButton1_Click()
Dim SciezkaPliku As Variant
Dim FileFilter As String
FileFilter = "Pixolus CSV (*.csv),*.csv"
SciezkaPliku = Application.GetOpenFilename(FileFilter)
With ThisWorkbook.Sheets(month(i)).QueryTables.Add(Connection:="TEXT;" & SciezkaPliku, Destination:=ThisWorkbook.Sheets(month(i)).Range("$A"))
.Name = "CAPTURE"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
ActiveWorkbook.Save
End With
MsgBox "Dane zostały dodane!"
'Worksheets("month(i)").Columns("D").Replace _ '
'What:=".", Replacement:=",", _ '
'SearchOrder:=xlByColumns, MatchCase:=True '
'Worksheets("month(i)").Columns("D").Select '
'Selection.NumberFormat = "0.00" '
End Sub
在 CommandButton1_Click()
中尝试将 所有 次出现的 month(i)
更改为 Me.Dane_miesiac.Value
。我还建议您养成在所有模块顶部使用 Option Explicit
的习惯。您可以手动执行此操作或在“Tools/Options”
中选中“要求变量声明”
我有两个用户窗体。带有月份名称的组合框和用于将 CSV 文件加载到从组合框列表中选择的月份的按钮。当我上传我的 CSV 文件时,总是在 Sheet(12).
中打印数据我想创建用户窗体以将 CSV 文件上传到选定的 Sheet 表单组合框列表。
目前 excel 文件中有 12 张带有月份名称的表格。也许我需要将我的工作表名称与这个 .AddItem 结合起来?
Private Sub Userform_Initialize()
Dim month(12) As String
Dim i As Integer
month(1) = "Styczeń"
month(2) = "Luty"
month(3) = "Marzec"
month(4) = "Kwiecień"
month(5) = "Maj"
month(6) = "Czerwiec"
month(7) = "Lipiec"
month(8) = "Sierpień"
month(9) = "Wrzesień"
month(10) = "Październik"
month(11) = "Listopad"
month(12) = "Grudzień"
Dim ws As Worksheet
For i = 1 To 12
UseForm_START.Dane_miesiac.AddItem month(i)
Next i
End Sub
Private Sub CommandButton1_Click()
Dim SciezkaPliku As Variant
Dim FileFilter As String
FileFilter = "Pixolus CSV (*.csv),*.csv"
SciezkaPliku = Application.GetOpenFilename(FileFilter)
With ThisWorkbook.Sheets(month(i)).QueryTables.Add(Connection:="TEXT;" & SciezkaPliku, Destination:=ThisWorkbook.Sheets(month(i)).Range("$A"))
.Name = "CAPTURE"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
ActiveWorkbook.Save
End With
MsgBox "Dane zostały dodane!"
'Worksheets("month(i)").Columns("D").Replace _ '
'What:=".", Replacement:=",", _ '
'SearchOrder:=xlByColumns, MatchCase:=True '
'Worksheets("month(i)").Columns("D").Select '
'Selection.NumberFormat = "0.00" '
End Sub
在 CommandButton1_Click()
中尝试将 所有 次出现的 month(i)
更改为 Me.Dane_miesiac.Value
。我还建议您养成在所有模块顶部使用 Option Explicit
的习惯。您可以手动执行此操作或在“Tools/Options”