我完全是个 VB 黑客 - 比如剪切/复制/粘贴并尝试让事情正常运作。下面的代码在我的 Windows 机器上运行良好,但在我的 Mac 上却无法运行。
我在此行收到文件/路径访问错误:
Open MYFILE & "C2NXT_STD.txt" For Output As #FileNum
我确信这是由于Open MYFILE
引用文件夹路径的部分造成的。也许我真的有权限错误?
Public Sub a_SaveAsTextWithDelimiter()
Const MYFILE = "Macintosh HD/Users/darrenmason/Documents/Products/Creator NXT/Serials/"
Dim Last_Column As Integer
Dim Last_Row As Long
Dim FileNum As Integer
Dim My_Range As Range
Dim My_Cell As Variant
FileNum = FreeFile
With ActiveSheet.Cells
Last_Column = .Find("*", [A1], , , xlByColumns, xlPrevious).Column
Last_Row = .Find("*", [A1], , , xlByRows, xlPrevious).Row
End With
Set My_Range = ActiveSheet.Range("A1:A" & Last_Row)
Open MYFILE & "C2NXT_STD.txt" For Output As #FileNum
For Each My_Cell In My_Range
If My_Cell.Row Mod 1000 = 0 Then
Close #FileNum
Open MYFILE & "C2NXT_STD_" & (My_Cell.Row \ 1000) & "_" & (Format(Date, "yyyymmdd")) & ".txt" For Output As #FileNum
End If
Print #FileNum, My_Cell.Value
Next
Close #FileNum
End Sub
答案1
尝试从路径中删除“Macintosh HD”,以便它以斜线开头。
IEConst MYFILE = "/Users/darrenmason/Documents/Products/Creator NXT/Serials/"