Results 1 to 2 of 2

Using VBA to export to a specific location on Mac

Threaded View

  1. #1
    Registered User
    Join Date
    03-02-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Using VBA to export to a specific location on Mac

    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
    Last edited by absolut_cdn; 03-03-2013 at 03:05 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1