Vba code working in windows 7 but fails after windows 10 update

kgartin

Board Regular
Joined
May 6, 2010
Messages
201
This code snippet worked fine in 7 but fails after upgrade to 10. I get "runtime error '5': Invalid call or argument" on fname = Dir:

Code:
        oldpath = "\\DSGAIN01\Commercial_Printing\Work Flow\WEEKLY PRESS-DIST REPORTS - COMM\02 JACKSONVILLE\" & BUNIT & "\"
        newpath = "\\DSGAIN01\Commercial_Printing\Work Flow\WEEKLY PRESS-DIST REPORTS - COMM\02 JACKSONVILLE\" & BUNIT & "\OUTSIDE DATE PARAM\"
        fname = Dir(oldpath & AWN)
            
        fnamea = oldpath & AWN
        fnameb = newpath & AWN
            
        If Len(Dir$(fnameb)) > 0 Then
            Kill (fnamea)
            GoTo SKIP
        End If
            
        Do While fname <> ""
            Name oldpath & fname As newpath & fname
            fname = Dir
        Loop


Any idea why?

I have a similar problem with another code (in that it worked in 7 but not in 10). This time I get "Compile error: Can't find project or library" on "Dim FileSys As FileSystemObject". Nothing's changed...only the upgrade (well, new computer that has Windows 10):

Code:
Sub PLANTER()

Dim FileSys As FileSystemObject
    Dim objFile As File
    Dim myFolder
    Dim strFilename, YEER As String
    Dim strFilename2 As String
    Dim dteFile As Date
    Dim FN As String
        
    YEER = Right(Range("A46"), 2)
        
    Const myDir As String = "\\DSGAIN01\Commercial_Printing\OSB Distribution\Leesburg Commercial Totals\Apopka " '"c:\Refresh"
    
    Set FileSys = New FileSystemObject
    Set myFolder = FileSys.GetFolder(myDir & YEER)
        
    dteFile = DateSerial(1900, 1, 1)
    For Each objFile In myFolder.Files
        If objFile.DateLastModified > dteFile Then
            dteFile = objFile.DateLastModified
            strFilename = objFile.PATH
            strFilename2 = objFile.Name
        End If
    Next objFile
    
    Application.ScreenUpdating = False
    Application.DisplayStatusBar = False
    Application.EnableEvents = False
    
    Workbooks.Open strFilename
     
    Dim WB As Workbook, WN As String, INS As Integer
    
    INS = ActiveWorkbook.Worksheets("Crew Sheet").Range("O29").Value
    
    For Each WB In Application.Workbooks
        If WB.Name Like "*PLANTER*" Then
            WB.Activate
        End If
    Next WB
    ActiveSheet.Range("D46") = INS
    Worksheets("BILLING FORM (NEW)").Shapes("TextBox 20").TextFrame.Characters.Text = strFilename2
    
    For Each WB In Application.Workbooks
        If WB.Name Like "PLanter*" Then
            WB.Close savechanges:=False
        End If
    Next WB
    
    Set FileSys = Nothing
    Set myFolder = Nothing
        
    Application.ScreenUpdating = True
    Application.DisplayStatusBar = True
    Application.EnableEvents = True
    
End Sub
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Yeah, its not available in later versions, the best thing to do with that is if you have your old version of excel (2007) I think then it may be worth installing on the new PC too as some features have been removed from later versions including
the datepicker, in fact if you can have it on this pc anyway, your macro will probably start working again
 
Upvote 0
Uncheck any references marked as MISSING, save and close the workbook, re-open it and try the code again.
 
Upvote 0
Uncheck any references marked as MISSING, save and close the workbook, re-open it and try the code again.

Yep did that before reading your comment and it worked!


Still having issues with fname = Dir in the other code. Any ideas anyone?
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

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