I am running OS X, Version 10.5.8, MS Office 2003 - I realize 08 does not have VBA and Macros abilities and I can't wait for 2011 to finish project. We want VBA process in Mac to be able to Go to a folder and give us all CSV files names that are in that folder. In Windows I would use this code: (and this code works on a PC but not on an iMac)
Option Explicit
Public Sub sub_import()
Dim fn As Variant, f As Integer
Dim I As Long, Pth As String
Dim iCnt As Integer
Dim sFile As String
'Stop Screen Updating
Application.ScreenUpdating = False
'open Dialog box
fn = Application.GetOpenFilename("CSV Files (*.csv), *.csv", _
1, "Select One Or More Files To Open", , True)
If TypeName(fn) = "Boolean" Then Exit Sub
'Loop through Files and import data
For f = 1 To UBound(fn)
Debug.Print "Selected file #" & f & ": " & fn(f)
I = I + 1
Pth = fn(f)
Call sub_srch_string(Pth, iCnt)
sFile = Right(Pth, Len(Pth) - iCnt)
Cells(I + 4, "I").Value = sFile
Pth = Left(Pth, Len(Pth) - (Len(sFile) + 1))
Next f
'Start Screen Updating
Application.ScreenUpdating = True
End Sub
Private Sub sub_srch_string(Pth As String, iCnt As Integer)
Dim x As Integer
'iCnt = 1
For x = 1 To Len(Pth)
If Mid(Pth, x, 1) = "\" Then
iCnt = x
End If
Next
End Sub
Anyone got a solution?
Option Explicit
Public Sub sub_import()
Dim fn As Variant, f As Integer
Dim I As Long, Pth As String
Dim iCnt As Integer
Dim sFile As String
'Stop Screen Updating
Application.ScreenUpdating = False
'open Dialog box
fn = Application.GetOpenFilename("CSV Files (*.csv), *.csv", _
1, "Select One Or More Files To Open", , True)
If TypeName(fn) = "Boolean" Then Exit Sub
'Loop through Files and import data
For f = 1 To UBound(fn)
Debug.Print "Selected file #" & f & ": " & fn(f)
I = I + 1
Pth = fn(f)
Call sub_srch_string(Pth, iCnt)
sFile = Right(Pth, Len(Pth) - iCnt)
Cells(I + 4, "I").Value = sFile
Pth = Left(Pth, Len(Pth) - (Len(sFile) + 1))
Next f
'Start Screen Updating
Application.ScreenUpdating = True
End Sub
Private Sub sub_srch_string(Pth As String, iCnt As Integer)
Dim x As Integer
'iCnt = 1
For x = 1 To Len(Pth)
If Mid(Pth, x, 1) = "\" Then
iCnt = x
End If
Next
End Sub
Anyone got a solution?