我在此报告中有一个模块功能,用于连接某些单元格:
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
答案 0 :(得分:2)
解决方法是,您必须将AnalysisResults
和Join
个函数另存为加载项文件.xlam
,然后在Developer->Add-ins
添加到Excel。这样做,上面的代码在没有#NAME?
这里发生的事情是,当excel尝试将文件保存为CSV时,它不知道AnalysisResults
函数是什么。