【问题标题】:How to Remove Quotes from Excel VBA Results如何从 Excel VBA 结果中删除引号
【发布时间】:2020-07-06 07:05:14
【问题描述】:

我正在学习(如果你可以称之为)Excel VBA。我正在使用的脚本会在每个生成的导出文件周围加上引号。例如,我希望结果是一个读取 HELLO WORLD 的 TXT 文件,但结果却是带有引号的“HELLO WORLD”。谁能指导我如何编辑脚本?这里是:

Sub ExportToTXT()
  Dim wsData As Variant
  Dim myFileName As String
  Dim FN As Integer
  Dim p As Integer, q As Long
  Dim path As String
  Dim myString As String
  Dim lastrow As Long, lastcolumn As Long
    
  lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
  lastcolumn = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
  path = "C:\Users\Mini Gyu\Desktop\GE-Region-Folders\"
  
  For p = 8 To lastcolumn
    wsData = Sheets("Sheet1").Cells(8, p).Value
    'If wsData = "" Then Exit Sub
    myFileName = ActiveSheet.Cells(1, p).Value
    myFileName = myFileName & ".txt"
    myFileName = path & myFileName
    'MsgBox myFileName
    myString = ""
    For q = 7 To lastrow
      myString = myString & Cells(q, p)
    Next q
    FN = FreeFile
    Open myFileName For Output As #FN
    Write #FN, myString
    Close #FN
  Next p

End Sub

谢谢!

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    请替换:

    Write #FN, myString
    

    Print #FN, myString
    

    【讨论】:

    • 你在这里就像一个忍者。我刚刚发布了这个!再次谢谢你~我会及时得到的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 2021-12-19
    相关资源
    最近更新 更多