flanmou
05-18-2021, 04:19 PM
Longtime VBA programmer, first time on a Mac. Having trouble understanding why this doesn't work. Specifically, when it gets to
While Not EOF(filenum), I get "Run-time error '52': Bad file name or number". However beforehand Excel opened a dialog box to confirm access to the file, so I know it's there. Also when I do "?Dir(filename)" in the immediate window it returns the filename.
I'm confused. Must be an OS X issue somehow but I'm not sure where or how. Any help would be greatly appreciated.
Function reload()
Dim desktop As String
Dim filename As String
Dim filenum As Integer
Dim file_line As String
Dim arr() As Variant
Dim i As Long
Dim j As Long
desktop = MacScript("return (path to desktop folder) as String")
filename = desktop & Range("Filename").Value
Sheets("Raw").Cells.Clear
Debug.Print (filename)
filenum = FreeFile()
i = 1
Open filename For Input As #filenum
While Not EOF(filenum)
Line Input #filenum, file_line
arr = Split(file_line, ",")
For j = LBound(arr, 1) To UBound(arr, 1)
Sheets("Raw").Cells(i, j) = arr(j)
Next j
i = i + 1
Wend
Close #1
End Function
While Not EOF(filenum), I get "Run-time error '52': Bad file name or number". However beforehand Excel opened a dialog box to confirm access to the file, so I know it's there. Also when I do "?Dir(filename)" in the immediate window it returns the filename.
I'm confused. Must be an OS X issue somehow but I'm not sure where or how. Any help would be greatly appreciated.
Function reload()
Dim desktop As String
Dim filename As String
Dim filenum As Integer
Dim file_line As String
Dim arr() As Variant
Dim i As Long
Dim j As Long
desktop = MacScript("return (path to desktop folder) as String")
filename = desktop & Range("Filename").Value
Sheets("Raw").Cells.Clear
Debug.Print (filename)
filenum = FreeFile()
i = 1
Open filename For Input As #filenum
While Not EOF(filenum)
Line Input #filenum, file_line
arr = Split(file_line, ",")
For j = LBound(arr, 1) To UBound(arr, 1)
Sheets("Raw").Cells(i, j) = arr(j)
Next j
i = i + 1
Wend
Close #1
End Function