Failing to Find File

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
So my code was working perfectly last week (when it ran for the first time. Now it says it can't find the "temp" folder that it created....and I see the folder on teh desktop. It's bugging out at the "Kill (TempFolderOLD) line. Ideas?

Code:
Sub Downloadx()Dim URL As String
Dim tstamp As String
Dim Folder0 As String
Dim Folder1 As String
Dim Folder2 As String
Dim folder3 As String
Dim Namer As String
Dim Date0 As String
Dim Date1 As String
Dim Date2 As String
Dim Date3 As String
Dim Divider As String
Dim LocalFilePath As String
Dim TempFolderOLD As String
Dim OldFinalName As String
Dim TempFileNEW As String
Dim DownloadStatus As Long
Dim LastRow As Long
Dim Finalname As String
Dim btn As Shape
Dim MyFSO As FileSystemObject
Set MyFSO = New Scripting.FileSystemObject


Dim rw As Long


    ' find last row of data in column B on 'Background'
    LastRow = Sheets("Background").Range("B" & Rows.Count).End(xlUp).Row


    ' loop through rows on 'Background'
    'For rw = 4 To LastRow
    For rw = 4 To Sheets("Background").Range("B" & Rows.Count).End(xlUp).Row
            
            With Sheets("Background")
            Namer = .Range("B" & rw)    'Pub name
            URL = .Range("I" & rw)      'URL to download
            Date0 = .Range("C" & rw)    'Week #
            Date1 = .Range("E" & rw)    'Year #
            Divider = .Range("D" & rw)  '\
            Date2 = .Range("G2")        'base week
            Date3 = .Range("I3")        'base year
        End With
        
        With Sheets("Setup")
            Folder0 = .Range("B5")    'temp folder (desktop)
            Folder1 = .Range("B7")    'permanent folder (desktop)
            Folder2 = .Range("C7")    'permanent folder
            folder3 = .Range("C5")    'temp Folder
        End With
        
        TempFolderOLD = Environ("Userprofile") & "\" & Folder0 & "\" & folder3 & "\"
        tstamp = Format(Now, "mm-dd-yyyy")
        TempFileNEW = TempFolderOLD & tstamp & Namer & ".pdf"
        LocalFilePath = Environ("Userprofile") & "\" & Folder1 & "\" & Folder2 & "\"
        Finalname = Namer & ".pdf"
        OldFinalName = LocalFilePath & Finalname
        
        
        'If these criteria are met, let's begin the download tree
        If Date0 <> Date2 And Date1 <> Date3 Then
    
            'Let's assign everything to the temp folder
            'Begin by clearing any possible undeleted/corrupted files from my "temp" folder
            If MyFSO.FileExists(TempFolderOLD) Then Kill (TempFolderOLD)
            'Make a new temp folder
            If (Dir(TempFolderOLD, vbDirectory)) = "" Then MkDir (TempFolderOLD)
            'Attempt download to the temp folder
            DownloadStatus = URLDownloadToFile(0, URL, TempFileNEW, 0, 0)
            'Check for proper download
            If DownloadStatus = 0 Then
                'Delete the old files
                If MyFSO.FileExists(OldFinalName) Then
                    Kill (OldFinalName)
                    MkDir (LocalFilePath)
                End If
                'Save temp files to replace old files
                'TempFileNEW.SaveAs Filename:=LocalFilePath, FileFormat:=xlTypePDF
                MyFSO.CopyFile Source:=TempFileNEW, Destination:=LocalFilePath
                'Now delete temp files
                Kill (TempFolderOLD)
                'Now update excel sheet to show download passed
                MsgBox "File Downloaded. Check in this path: " & LocalFilePath
                
                With Sheets("Background")
                    .Range("F" & rw) = tstamp
                    .Range("G" & rw) = "SAT"
                    .Range("C" & rw) = Format(Now, "ww", vbWednesday)
                    .Range("E" & rw) = Format(Now, "yy")
                    'date formating
                    .Range("C" & rw).HorizontalAlignment = xlRight
                    .Range("D" & rw).HorizontalAlignment = xlGeneral
                    .Range("E" & rw).HorizontalAlignment = xlLeft
                End With
                
                'If download failed, update excel to show- old files should NOT have been deleted yet but the temp file should be deleted
            Else:
                MsgBox "Download File Process Failed"
                Sheets("Background").Range("G" & rw) = "FAIL"
                If MyFSO.FileExists(TempFolderOLD) Then
                Kill (TempFolderOLD)
                End If
            End If
            'If the original criteria were met and the download was not necessary, say so
        Else


            MsgBox "The most up to date pub has been downloaded"
        End If
        
    Next rw


End Sub
 
Last edited:
Normally this folder is used to store macro-enabled files which auto-start with excel. But nothing will end up there on its own.
Normally you should always check (esp. when having a problem) what files are loaded - visible or not: in VBE - Project Explorer - it shows them all

Glad you figured it out.
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
and I lied....didn't solve it the next time I went to use excel...

So I removed all of the code from the ThisWorkBook page- most of which were macros for running when opening/closing. This hasn't changed excel- so I'm back to wondering if this was an installation problem
 
Upvote 0
I had a similar problem some time ago but it was caused by an add-in I am building up from time to time. Changing a few settings in excel fixed it for me.
I doubt it is an installation issue, although a reinstall may fix it. Probably something else is loading in the background causing this. Disabling graphics hardware acceleration and changing DDE settings helped in my case .

Check the list of loaded workbooks and addins in VBE(Alt+F11) / Project Explorer (Ctrl+R) - if anything is out-of-place or just in case try to disable /remove everything but the current workbook and check for a change.
However strange this may seem - check if the workbook is not back in the XLSTART folder.
Also check and disable all other addins one-at-a-time: Excel Options / Add-ins / Manage
 
Last edited:
Upvote 0
So I had thought along similar lines as you-

already disabled all addins- namely just solver
already checked workbooks/projects, and the XLSTART folder is clear.

So interesting because I just went back to double check everything- so workbook on the desktop- double click to open- excel opens a blank window- checking- there's no workbook open and vba says no workbook as well just to confirm. Double click the workbook again and it opens as it should (this has been acting the same all along, but just to clarify to myself...)
 
Upvote 0
Nothing in that forum to work :/

And no- if I close the window and then attempt to reopen the workbook I get the blank, open window (unloaded excel window)
 
Upvote 0
did you try checking the File type association?
Is it only this file (of the same type e.g. xlsm) that behaves like this? if YES then don't bother with the above and maybe upload a copy of the file so that me or someone else can inspect it.
Although from what you say I gather that the file only loads if the app i pre-loaded. Which is weird and means something at application level - still not sure what it can be ...


What is the file location (path and file name)?
Did you check your trust center settings?
What is your system setup - OS, Office, version ?
 
Last edited:
Upvote 0
OS - Windows 10 Pro
Office 2016 Professional Plus - build- 11601.20144 (version 1904)

Path was desktop (C:\Users\Austen\Desktop\**myworkbook**

File type assocation- so it seemed like it was just .xlsm (i.e. this workbook) but tweaking DDE and graphics seems to make it worse- now the only way to actually load a workbook is to open excel and the from within the excel window, open a workbook. Clicking the icon again won't open excel....not good.

I am happy to send you the workbook personally. I'll pm you my email and you can shoot me an email and I'll return it with the workbook. I very much appreciate your help.

Also note- this laptop that is having this issue is not connected to the internet...and won't be until Tuesday at the earliest. I can transfer stuff to it via flash drive though.

I don't see anything out of the ordinary in trust center settings.
No add-ins active now.
Graphics Acceleration disabled. DDE not checked
 
Upvote 0
just sent you a PM with my mail address

Fix you settings back to normal if it's not helping.
Can you confirm one more thing.
When you first open the file and you end up with a blank Excel window - in the VIEW tab, next to Freeze panes there is a button labeled UNHIDE - is it active or grayed out?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,485
Members
448,967
Latest member
visheshkotha

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