Hi, I'm really new to VBA, and I'm trying write a macro that will save the contents of some specifc cells to a specific location on my Mac. The whole code works fine, EXCEPT that it won't save to the right location; all files save to the desktop.
Basically, A1 starts out containing something like this "260 - CategoryA - 555.555.555.555 - 2012-11-06 17:43:49," and I want the macro to save the contents of column A, rows 2-61 to a text file named after the first 3 numbers in cell A1. The location I want it to save to depends on whether cell A1 originally contains the text "CategoryA" or "CategoryB". Again, it export the data to a text file just fine, but will only save to the desktop.
Any help would be great!
Public Sub Columns_2_TextFile()
Const My_Path1 = "Users:Username:Desktop:Folder1"
Const My_Path2 = "Users:Username:Desktop:Folder2"
Dim iCol As Integer
Dim lRow As Long
Dim File_Num As Long
Dim SaveDest As String
On Error Resume Next
If InStr(1, Cells(1, 1).Value, "CategoryA", vbTextCompare) > 0 Then
If Trim(Dir(My_Path1, vbDirectory)) = "" Then
MkDir My_Path1
Else
Kill My_Path1 & "*.txt"
End If
ElseIf InStr(1, Cells(1, 1).Value, "CategoryB", vbTextCompare) > 0 Then
If Trim(Dir(My_Path2, vbDirectory)) = "" Then
MkDir My_Path2
Else
Kill My_Path2 & "*.txt"
End If
End If
On Error GoTo 0
File_Num = FreeFile
With ActiveSheet
Cells(1, 1).Value = Left(Cells(1, 1), 3)
Open Trim(.Cells(1, 1).Value) & ".txt" For Output As #File_Num
For lRow = 2 To 61
Print #File_Num, .Cells(lRow, 1).Value
Next
Close #File_Num
End With
End Sub
Bookmarks