我在此报告中有一个模块功能,可将某些单元格连接起来:

Function AnalysisResults(Specs As Range, Results As Range)
    AnalysisResults = Join(Specs) & ";" & Replace(Join(Results), ",", ".")
End Function

Private Function Join(Range As Range, Optional ByRef Delimeter As String = " ")
    Dim Str As String
    For Each cell In Range
        If Str <> "" Then Str = Str & Delimeter
        Str = Str & cell.Value
    Next

    Join = Str
End Function


然后我有一个命令按钮,将我的文件另存为CSV。它可以工作,但是功能单元格中保存值的位置是#NAME?。
如果我将另存为以逗号分隔的CSV格式,则会正确保存并显示公式值。

这是CommandButton的代码:

   Dim myValue As Variant
myValue = InputBox("Specifica numele WBT-ului de descarcare:", "Save WBT with the following name", 1)
Range("L2").Value = myValue
Dim CopyToCSV()
Dim MyPath As String
Dim MyFileName As String
Sheets("Manual Discharge WBT").EnableCalculation = True
MyPath = "\\FILES\Transfer\~~TTS Import (do not delete)~~\Import Files\"
MyFileName = Range("L2") & " Discharge " & Format(CStr(Now), " dd_mm_yyyy_hh_mm")
If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"
Sheets("Manual Discharge WBT").Copy
With ActiveWorkbook
    .SaveAs Filename:= _
        MyPath & MyFileName, _
        FileFormat:=xlCSVWindows, _
        CreateBackup:=False
    .Close False
     MsgBox "Fisierul tau s-a salvat ca: " & MyFileName
End With

最佳答案

解决方案是,您将必须将AnalysisResultsJoin函数另存为加载文件.xlam,并在Developer->Add-ins处添加到excel。这样,上面的代码在没有#NAME?的情况下保存为CSV时对我有用

这里发生的是,当excel试图将文件保存为CSV时,它不知道AnalysisResults函数是什么。

关于vba - 另存为CSV格式将文件另存为#NAME吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39264989/

10-12 14:18