有关VB中CSV文件,我把TEXT1的值命名建一个CSV文件,然后把TEXT1~TEXT9的值同一行中按列加入并保存,但
源代码:PrivateSubCommand6_Click()Open"D:\"&Text1.Text&".csv"ForOutputAs#1Close#1DimexAsN...
源代码:Private Sub Command6_Click()
Open "D:\" & Text1.Text & ".csv" For Output As #1
Close #1
Dim ex As New Excel.Application
Dim exb As Excel.Workbook
Dim exs As Excel.Worksheet
Set exb = ex.Workbooks.Open("D:\" & Text1.Text & ".CSV ")
ex.Visible = True
Set exs = exb.Worksheets(1)
exs.Select
exs.Cells(1, 1) = Text1.Text
exs.Cells(1, 2) = Text2.Text
exs.Cells(1, 3) = Text3.Text
exs.Cells(1, 4) = Text4.Text
exs.Cells(1, 5) = Text5.Text
exs.Cells(1, 6) = Text6.Text
exs.Cells(1, 7) = Text7.Text
exs.Cells(1, 8) = Text8.Text
exs.Cells(1, 9) = Text9.Text
exb.Close True
Set exs = Nothing
Set exb = Nothing
Set ex = Nothing
End Sub
但运行后,9个值全跑到一列去了,请大侠们多指教,谢谢! 展开
Open "D:\" & Text1.Text & ".csv" For Output As #1
Close #1
Dim ex As New Excel.Application
Dim exb As Excel.Workbook
Dim exs As Excel.Worksheet
Set exb = ex.Workbooks.Open("D:\" & Text1.Text & ".CSV ")
ex.Visible = True
Set exs = exb.Worksheets(1)
exs.Select
exs.Cells(1, 1) = Text1.Text
exs.Cells(1, 2) = Text2.Text
exs.Cells(1, 3) = Text3.Text
exs.Cells(1, 4) = Text4.Text
exs.Cells(1, 5) = Text5.Text
exs.Cells(1, 6) = Text6.Text
exs.Cells(1, 7) = Text7.Text
exs.Cells(1, 8) = Text8.Text
exs.Cells(1, 9) = Text9.Text
exb.Close True
Set exs = Nothing
Set exb = Nothing
Set ex = Nothing
End Sub
但运行后,9个值全跑到一列去了,请大侠们多指教,谢谢! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询