excel中的文件保存
单击按钮将工作簿内容保存到txt文件中时,会编写一段代码 代码: 工作簿中的原始行: 创建表abc,从rpt2中选择rpt2_id、rpt2_usgcount、rpt2_usgdate、rpt2_usgmins,其中rpt2_id='xyz 产出如下: 创建表abc,从rpt2中选择rpt2_id、rpt2_usgcount、rpt2_usgdate、rpt2_usgmins,其中rpt2_id='xyz 输出在开始和结束处带有双引号,并且仅用于工作簿中的insert和create语句excel中的文件保存,excel,vba,Excel,Vba,单击按钮将工作簿内容保存到txt文件中时,会编写一段代码 代码: 工作簿中的原始行: 创建表abc,从rpt2中选择rpt2_id、rpt2_usgcount、rpt2_usgdate、rpt2_usgmins,其中rpt2_id='xyz 产出如下: 创建表abc,从rpt2中选择rpt2_id、rpt2_usgcount、rpt2_usgdate、rpt2_usgmins,其中rpt2_id='xyz 输出在开始和结束处带有双引号,并且仅用于工作簿中的insert和create语句 有谁能帮
有谁能帮我不在输出中引用这些话吗?虽然你特别要求彼得的帮助,但看看这是否是你想要的
xlSheet.SaveAs Filename:=strOutputFileName, FileFormat:=xlTextPrinter
评论的后续行动
试试这个
Private Sub CommandButton1_Click()
Dim xlBook As Workbook, xlSheet As Worksheet
Dim strOutputFileName As String
Dim n As Long, i As Long, j As Long
Dim MyData As String, strData() As String, MyArray() As String
Dim strPath As String
strPath = ActiveWorkbook.Path '<~~ \\plyalnppd3sm\d$\Temp\Arun\TAT\
ThisWorkbook.SaveCopyAs strPath & "\Temp.xls"
Set xlBook = Workbooks.Open(strPath & "\Temp.xls")
For Each xlSheet In xlBook.Worksheets
If xlSheet.Name <> "User_provided_data" Then
strOutputFileName = strPath & "\" & xlSheet.Name & ".zup"
xlSheet.SaveAs Filename:=strOutputFileName, FileFormat:=xlTextMSDOS
n = n + 1
ReDim Preserve MyArray(n)
MyArray(n) = strOutputFileName
Debug.Print strOutputFileName
End If
Next
xlBook.Close SaveChanges:=False
Kill strPath & "\Temp.xls"
For i = 1 To UBound(MyArray)
'~~> open the files in One go and store them in an array
Open MyArray(i) For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
strData() = Split(MyData, vbCrLf)
'~~> Write to the text file
Open MyArray(i) For Output As #1
'~~> Loop through the array and check if the start and end has "
'~~> And if it does then ignore those and write to the text file
For j = LBound(strData) To UBound(strData)
If Left(strData(j), 1) = """" And Right(strData(j), 1) = """" Then
strData(j) = Mid(strData(j), 2, Len(strData(j)) - 2)
End If
Print #1, strData(j)
Next j
Close #1
Next i
End Sub
虽然你已经明确要求彼得的帮助,但看看这是否是你想要的
xlSheet.SaveAs Filename:=strOutputFileName, FileFormat:=xlTextPrinter
评论的后续行动
试试这个
Private Sub CommandButton1_Click()
Dim xlBook As Workbook, xlSheet As Worksheet
Dim strOutputFileName As String
Dim n As Long, i As Long, j As Long
Dim MyData As String, strData() As String, MyArray() As String
Dim strPath As String
strPath = ActiveWorkbook.Path '<~~ \\plyalnppd3sm\d$\Temp\Arun\TAT\
ThisWorkbook.SaveCopyAs strPath & "\Temp.xls"
Set xlBook = Workbooks.Open(strPath & "\Temp.xls")
For Each xlSheet In xlBook.Worksheets
If xlSheet.Name <> "User_provided_data" Then
strOutputFileName = strPath & "\" & xlSheet.Name & ".zup"
xlSheet.SaveAs Filename:=strOutputFileName, FileFormat:=xlTextMSDOS
n = n + 1
ReDim Preserve MyArray(n)
MyArray(n) = strOutputFileName
Debug.Print strOutputFileName
End If
Next
xlBook.Close SaveChanges:=False
Kill strPath & "\Temp.xls"
For i = 1 To UBound(MyArray)
'~~> open the files in One go and store them in an array
Open MyArray(i) For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
strData() = Split(MyData, vbCrLf)
'~~> Write to the text file
Open MyArray(i) For Output As #1
'~~> Loop through the array and check if the start and end has "
'~~> And if it does then ignore those and write to the text file
For j = LBound(strData) To UBound(strData)
If Left(strData(j), 1) = """" And Right(strData(j), 1) = """" Then
strData(j) = Mid(strData(j), 2, Len(strData(j)) - 2)
End If
Print #1, strData(j)
Next j
Close #1
Next i
End Sub
上次peter帮助我找到了与excel相关的解决方案。如果他能在这方面帮助我,请遵循@SiddharthRout的建议,并在这里查看:祝你好运!上次peter帮助我找到了与excel相关的解决方案。如果他能在这方面帮助我,请遵循@SiddharthRout的建议,并在这里查看:祝你好运@user207517请注意限制:@user207517:这是因为它超过256个字符。请参阅上面给出的链接中的限制。我可以给你一个替代代码,如果你愿意,它可以从开头和结尾删除?@user207517如果你遵循这个链接,你会找到一个建议的解决方案来绕过这个限制。此外,这是另一个问题。当你到家时把文件寄给我,然后我们从那里取走?我相信这些错误是由于模块modAddinHi Siddharth中的其他错误造成的。我一到家就会给你发送excel。同时,如果你能用我在输出中得到的上述错误对我进行排序,那么输出将生成为@user207517。请注意限制:@user207517:那就是是因为它超过了256个字符。请参阅上面给出的链接中的限制。我可以给你一个替代代码,如果你愿意,它可以从开头和结尾删除?@user207517如果你遵循这个链接,你会找到一个建议的解决方案来绕过这个限制。此外,这是另一个问题。当你到家时把文件寄给我,然后我们从那里取走?我相信这些错误是由于模块modAddinHi Siddharth中的一些其他错误造成的。我一到家就会给你发送excel。同时,如果你能用我在输出中得到的上述错误对我进行排序,那么输出将按如下方式生成