Mac上的Excel 2011 - 宏 - FileCopy文件名长度限制

时间:2016-02-28 03:12:09

标签: excel vba excel-vba excel-vba-mac

我使用下面的宏从文件夹中复制图像"图像"基于从C列到新创建的文件夹的图像代码,按列A的内容命名。宏在Windows上没有任何问题,但看起来在Mac Excel的图像文件名中有25个字符的限制。任何想法如何解决这个问题?

Sub copy into individual folder()
Sheets(1).Select
Dim R As Range
Dim RootFolder As String
RootFolder = ""  '<<< CHANGE 1
For Each R In Range("A4:A500") '<<< CHANGE 2
    If Len(R.Text) > 0 Then
        On Error Resume Next
        ChDir ActiveWorkbook.Path
        MkDir ActiveWorkbook.Path & Application.PathSeparator & Left(R.Text, 6)
        Dim fn As String
        myDir = ActiveWorkbook.Path & Application.PathSeparator & "IMAGES" '<- alter here
        'Debug.Print "Image directory " & myDir
        ChDir myDir
        newFolder = ActiveWorkbook.Path & Application.PathSeparator & Left(R.Text, 6) '<- alter here
        'Debug.Print "Image code: " & Range("C" & R.Row).Text
        Search = myDir & Application.PathSeparator & "*" & Trim(Range("C" & R.Row).Text) & "*"
        found = 0
        fn = Dir("")
        Do While fn <> ""
            If InStr(fn, Range("C" & R.Row).Text) Then
                'Debug.Print "Copying file " & fn & " to " & newFolder
                'Debug.Print myDir & Application.PathSeparator & fn
                'Debug.Print newFolder & Application.PathSeparator & fn
                FileCopy myDir & Application.PathSeparator & fn, newFolder & Application.PathSeparator & fn
                found = 1
            End If
            fn = Dir
            'Debug.Print "File in images folder: " & fn
            'Debug.Print fn
        Loop
        If found = 0 Then
            R.Interior.ColorIndex = 3
        End If
    End If
Next R
End Sub

0 个答案:

没有答案