MAC Excel 2011 VBA File Name Limit of DIR function

DWhit217

New Member
Joined
Mar 29, 2012
Messages
21
I'm running into an issue where I can't use VBA to open a file to inject new data unless the filename is shorter than I believe 28 characters.

Is there a workaround for this?

Below is my code for reference.

Rich (BB code):
Sub FactorChange_Price()
    Dim MyPath As String, FilesInPath As String
    Dim MyFiles() As String, Fnum As Long
    Dim Filename As String
    Dim mybook As Workbook
    Dim CalcMode As Long
    Dim sh As Worksheet
    Dim ErrorYes As Boolean


    'Fill in the path\folder where the files are
    MyPath = Application.ActiveWorkbook.<wbr>Path & ":Update:"


    'If there are no Excel files in the folder exit the sub
    FilesInPath = Dir(MyPath)
    If FilesInPath = "" Then
        MsgBox "No files found"
        Exit Sub
    End If


    'Fill the array(myFiles)with the list of Excel files in the folder
    Fnum = 0
    Do While FilesInPath <> ""
        Fnum = Fnum + 1
        ReDim Preserve MyFiles(1 To Fnum)
        MyFiles(Fnum) = FilesInPath
        FilesInPath = Dir()
    Loop


    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        .EnableEvents = False
    End With


    'Loop through all files in the array(myFiles)
    If Fnum > 0 Then
        For Fnum = LBound(MyFiles) To UBound(MyFiles)
            Set mybook = Nothing
            On Error Resume Next
            Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))


            If Not mybook Is Nothing Then




                'Change cell value(s) in one worksheet in mybook
                With mybook.Worksheets("Project")

.Range("A1").Value = "Success"​
.Range("O63:O73").Value = .Range("O63:O73").Value + Workbooks("Master_Key").<wbr>Worksheets("Master_Key").<wbr>Range("D4:D14").Value .Range("G25") = Format(Now(), "mm-dd-yy") .Range("H25") = Format(Workbooks("Master_Key.<wbr>xlsm").Worksheets("Master_Key"<wbr>).Range("C27").Value, "mm-dd-yy") .Range("I25") = Format(Workbooks("Master_Key.<wbr>xlsm").Worksheets("Master_Key"<wbr>).Range("D27").Value, "mm-dd-yy") End With Application.Calculate Filename = Range("C11") ActiveWorkbook.<wbr>ChangeFileAccess Mode:=xlReadWrite Application.ActiveWorkbook.<wbr>SaveAs Application.ActiveWorkbook.<wbr>Path & ":" & Filename, FileFormat:=53 mybook.Close savechanges:=False End If Next Fnum End If With Application .ScreenUpdating = True .EnableEvents = True .Calculation = CalcMode End With End Sub
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top