Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何使用单击按钮将工作簿保存到txt文件中_Excel_Vba - Fatal编程技术网

Excel 如何使用单击按钮将工作簿保存到txt文件中

Excel 如何使用单击按钮将工作簿保存到txt文件中,excel,vba,Excel,Vba,需要将电子表格中的工作簿保存到我所在位置的单独txt文件中 但我在点击按钮时使用的代码是将数据传送到所需的位置,文件中包含我不感兴趣的特殊字符 当我在打印预览屏幕中获取详细信息时,任何人都可以帮助我获取txt文件 使用的代码: Private Sub CommandButton1_Click() Dim xlApp As Object Dim xlBook As Object Dim xlSheet As Object Dim strOutputFileName Set xlAp

需要将电子表格中的工作簿保存到我所在位置的单独txt文件中

但我在点击按钮时使用的代码是将数据传送到所需的位置,文件中包含我不感兴趣的特殊字符

当我在打印预览屏幕中获取详细信息时,任何人都可以帮助我获取txt文件

使用的代码:

Private Sub CommandButton1_Click()
Dim xlApp As Object
  Dim xlBook As Object
  Dim xlSheet As Object
  Dim strOutputFileName
  Set xlApp = CreateObject("Excel.Application")
  Set xlBook = xlApp.Workbooks.Open("C:\Documents and Settings\bera02a\Desktop\Arun_TAT_Testing_orig_14022013.xls")
  For Each xlSheet In xlBook.Worksheets
    strOutputFileName = "C:\Documents and Settings\bera02a\Desktop\" & xlSheet.Name & ".txt"
    xlSheet.SaveAs strOutputFileName
  Next
  xlApp.Quit

End Sub

我认为输出不正确的原因是没有指定所需的保存格式。尝试用以下代码替换保存行:

xlSheet.SaveAs Filename:=strOutputFileName, FileFormat:=xlUnicodeText

这将把输出定义为Unicode文本文件-我想这就是您想要的。

请指定/提供您对输出不感兴趣的这些特殊字符的示例?这是保存的文本文件中输出的摘录。这是保存的文本文件中输出的摘录。我的文件包含一些逗号和)符号,但不是上面所说的。在检查工作簿的打印预览时,我得到了输出。但在保存时,我无法得到。急需的帮助可爱…它工作了…非常感谢你的帮助彼得..我很高兴happy@user2075017这里最好的感谢是绿蜱)很乐意帮忙!还有一个要求。。我已经按照前面提到的路径生成了输出。如何将输出生成到excel显示的同一位置此:
strOutputFileName=xlBook.Path&“\”&xlSheet.Name&“.txt”
将TXT保存到与原始工作簿相同的文件夹中。是的..这很好,我认为原始路径文件需要更改为..并且应该使用什么来代替此设置xlBook=xlApp.Workbooks.Open(“C:\Documents and Settings\bera02a\Desktop\Arun\u TAT\u Testing\u orig\u 14022013.xls”)