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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
If its a new pc maybe you need to go into tools in the vb editor, Referneces and ensure the microsoft scripting runtime is checked
 
Last edited:
Upvote 0
These are my selections under References in VBA:

2xUULhsB5JjmC3BgZ52m7BwCO8VBBXCWrUC47M6VPHfLBBKPNQ_3n23tswbr0QNxO2KmwoScoi0wRl0Y7mCs=w1920-h949


view
 
Last edited:
Upvote 0
Nothing posted Microsoft Scripting Runtime needs to be checked not highlighted, actual tick in the box
 
Upvote 0
not sure then if it worked before you could try

Dim FileSys As Scripting.FileSystemObject
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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