none
File Already Exists Message RRS feed

  • General discussion

  • I have code that copies files from previous month folder to current month folder and renames files accordingly for the new month.

    At the end of the renaming sequence, I'm receiving a message that says file name already exists.  Using a message box to show the file name, I found that the code is seeing a file ~$VFF, as if there is a temporary file in the folder or a file that didn't save properly.

    Looking at the source folder and destination folder, I do not see any ~$VFF file.  I changed the folder options to show hidden files, etc.

    The original file wasn't open at the time of running the code.  I've manually opened the source file and there aren't any issues with the file when opening or saving it.

    Anyone have suggestions as to why the code is seeing this "invisible file"??

    Thanks in advance.

    JM Data Consultant

    Wednesday, September 17, 2014 7:35 PM

All replies

  • Hello JM,

    What code do you use for renaming and using files? Did you try to debug the code?

    Finally, how is it related to Outlook? Do you develop an Outlook add-in?

    Wednesday, September 17, 2014 9:29 PM
  • Hi JMData,

    According to your description, supposes there is already a file with the same name in the folder.

    What is your application? Is the folder you mentioned an Outlook folder?

    If you are developing an application that is used to copy files in Windows hard disk, I'm afraid it is not in our scope.

    It would be better if you give us more information about your application, I will move this thread to more suitable forum.

    Regards,

    George.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 18, 2014 7:58 AM
    Moderator
  • To Answer George & Eugene,

    I've set up code in Outlook to copy files from hard drive folder to a new hard drive folder, rename them with current month date, and create Outlook Tasks based on the files in the folder.

    Previous months this has worked no problem.  It appears that there is a temporary file remaining in the directory and causing the Filename already exists message.  I've tried showing all files in the directory to see if I can see the file from Explorer, but I simply don't see it.

    Is there an CACHE in Outlook VBA that possible is seeing a file that could be causing this?

    Thanks.

    JMData Consultant

    Thursday, September 18, 2014 1:39 PM
  • If these are not Outlook files (.PST, .OST, etc.) then Outlook wouldn't have any locks or other knowledge of the files. If you're just using VBA or Scripting code to copy/move the files Outlook isn't involved at all, other than hosting your VBA code.

    As long as the files aren't being saved in Outlook's <SecureTemp> folder it would appear to be code related. Show the relevant code.

    Also, if your code can see the file why not write a quick hack to delete it?


    Ken Slovak MVP - Outlook

    Thursday, September 18, 2014 7:57 PM
    Moderator
  • > Is there an CACHE in Outlook VBA that possible is seeing a file that could be causing this?

    No, there is no any cache. What code do you use for renaming and moving files?

    Friday, September 19, 2014 8:57 AM
  • The code for everything is listed below:

    Sub NewMonthlyCloseTaskList()
        
        MSG1 = MsgBox("EXECUTE NEXT MONTH CLOSE LIST?", vbYesNo, "EXECUTE CODE?")
        
        If MSG1 = vbYes Then
              
        Excel.Application.Speech.Speak "CLOSE TASK - MAKE DIRECTORIES - STARTING"
        makedirectories ' Creates Current Month Close Directory
        Excel.Application.Speech.Speak "CLOSE TASK - MAKE DIRECTORIES - COMPLETED"
        Excel.Application.Speech.Speak "CLOSE TASK - COPY CLOSE FILES - STARTING"
        CopyCloseFiles ' Copies Previous Close Month's Files to Current Month Folder
        Excel.Application.Speech.Speak "CLOSE TASK - COPY CLOSE FILES - COMPLETED"
        Excel.Application.Speech.Speak "CLOSE TASK - RENAME COPIED FILES - STARTING"
        RenameCopiedCloseFiles ' Renames Previous Close Month's Files to Current Month
        Excel.Application.Speech.Speak "CLOSE TASK - RENAME COPIED FILES - COMPLETED"
        Excel.Application.Speech.Speak "CLOSE TASK - ENTER CLOSE FILES AS TASKS - STARTING"
        EnterCloseFilesAsTask ' Takes the files in the current directory and makes them task Items in Monthly Close Task List with Hyperlinks to the file's location
        Excel.Application.Speech.Speak "CLOSE TASK - ENTER CLOSE FILES AS TASKS - COMPLETED"
        Else
        End If
    End Sub
    Sub EnterCloseFilesAsTask()
        Dim objFSO As Object
        Dim objFolder As Object
        Dim OBJFILE As Object
        
        Dim Enddate As Date
        Dim ROW As Integer
        Dim MONTHENDDATE As Date
        Dim PrevMonth As Date
                
        Dim Today As Date
        Today = Date
        CurrentMonth = WorksheetFunction.EoMonth((Now()), 0)
        'MsgBox Format(Today, "MM/DD/YYYY")
        Dim ParentDirectory As String ' 1st level directory
        Dim ChildDirectory As String ' 2nd level directory
        Dim MonthlyDirectory As String ' 3rd Level Directory
        Dim InventoryDirectory As String '4th Level Directory
        Dim objApp As Outlook.Application
        Dim defaultTasksFolder As Outlook.MAPIFolder
        Dim subFolder As Outlook.MAPIFolder
        Dim objNS As Outlook.NameSpace
        Dim objItm As TaskItem
        Set objApp = CreateObject("Outlook.Application")
    
        Set objNS = objApp.GetNamespace("MAPI")
        Set defaultTasksFolder = objNS.GetDefaultFolder(olFolderTasks)
        Set subFolder = defaultTasksFolder.Folders("CLOSE TASKS")
    
        
        ParentDirectory = "W:\MONTHLY CLOSE WORKPAPERS"
        ChildDirectory = ParentDirectory & "\FY" & Format(CurrentMonth, "YYYY") & " Financial Close Workbook"
        MonthlyDirectory = ChildDirectory & "\FY" & Format(CurrentMonth, "YYMM") & "_" & Format(CurrentMonth, "MMM")
        
        CurrentMonthDirectory = MonthlyDirectory
        MONTHENDDATE = WorksheetFunction.EoMonth((Date - 1), -1)
         
        Set objFSO = CreateObject("Scripting.FileSystemObject")
            
         'Get the folder object associated with the directory
        Set objFolder = objFSO.GetFolder(MonthlyDirectory)
        Enddate = Date
             
         'Loop through the Files collection
        
           
        For Each OBJFILE In objFolder.files
            Dim objinsp As Object
            
            Set objItm = subFolder.items.Add(olTaskItem)
            With objItm
                
               .Subject = OBJFILE.Name
               .Body = "<file://" & MonthlyDirectory & "\" & OBJFILE.Name & ">"
               .DueDate = Format(CurrentMonth, "mm/dd/yy")
               .Save
             End With
            
        Next
        
    End Sub
    Sub RenameCopiedCloseFiles()
        Dim objFSO As Object
        Dim objFolder As Object
        Dim OBJFILE As Object
        
        Dim MONTHENDDATE As Date
        Dim PrevMonth As Date
        Dim NEXTMONTH As Date
        
        Dim STRINGNAME As String
        
        Dim oldname, newname As String
                        
        Dim Today As Date
        Today = Date
        PrevMonth = WorksheetFunction.EoMonth((Today), -1)
        NEXTMONTH = WorksheetFunction.EoMonth((Today), 0)
        
    
        Dim ParentDirectory As String ' 1st level directory
        Dim ChildDirectory As String ' 2nd level directory
        Dim MonthlyDirectory As String ' 3rd Level Directory
     
        ParentDirectory = "W:\MONTHLY CLOSE WORKPAPERS"
        ChildDirectory = ParentDirectory & "\FY" & Format(NEXTMONTH, "YYYY") & " Financial Close Workbook"
        MonthlyDirectory = ChildDirectory & "\FY" & Format(NEXTMONTH, "YYMM") & "_" & Format(NEXTMONTH, "MMM")
        
        'MsgBox MonthlyDirectory, , "MONTHLY DIRECTORY IS:"
        
    
        MONTHENDDATE = WorksheetFunction.EoMonth((Date - 1), 0)
         
        Set objFSO = CreateObject("Scripting.FileSystemObject")
            
         'Get the folder object associated with the directory
        Set objFolder = objFSO.GetFolder(MonthlyDirectory)
        Enddate = Date
             
         'Loop through the Files collection
        For Each OBJFILE In objFolder.files
               
        ' Get New File Name for File *** WORKS BY ITSELF
            STRINGNAME = WorksheetFunction.Substitute(OBJFILE.Name, "FY" & Format(PrevMonth, "YYMM") & "_" & Format(PrevMonth, "MMM"), "FY" & Format(NEXTMONTH, "YYMM") & "_" & Format(NEXTMONTH, "MMM"))
            STRINGNAME = WorksheetFunction.Substitute(STRINGNAME, Format(PrevMonth, "MMMM"), Format(NEXTMONTH, "MMMM"))
            STRINGNAME = WorksheetFunction.Substitute(STRINGNAME, Format(PrevMonth, "MMM"), Format(NEXTMONTH, "MMM"))
            STRINGNAME = WorksheetFunction.Substitute(STRINGNAME, Format(PrevMonth, "YYYY-MM-DD"), Format(NEXTMONTH, "YYYY-MM-DD"))
            STRINGNAME = WorksheetFunction.Substitute(STRINGNAME, Format(PrevMonth, "YYYY-MM"), Format(NEXTMONTH, "YYYY-MM"))
            
            
           MsgBox OBJFILE.Name & " is now " & STRINGNAME
           
        ' RENAME
            With OBJFILE.Name
                Name MonthlyDirectory & "\" & OBJFILE.Name As MonthlyDirectory & "\" & STRINGNAME
            End With
        Next
    
    End Sub
    Sub CopyCloseFiles()
    
        Dim fso As Object
        Dim FromPath As String
        Dim topath As String
        Dim Fdate As Date
        Dim FileInFromFolder As Object
        Dim Today As Date
        Today = WorksheetFunction.EoMonth((Now() - 1), 0)
    'MsgBox Format(Today, "MM/DD/YYYY")
     
        Dim PrevMonthlyDirectory As String
        Dim PrevMonthDate As Date
        Dim PrevMonthChildDirectory
        
        Dim ParentDirectory As String ' 1st level directory
        Dim ChildDirectory As String ' 2nd level directory
        Dim MonthlyDirectory As String ' 3rd Level Directory
        Dim InventoryDirectory As String '4th Level Directory
        
        ParentDirectory = "W:\MONTHLY CLOSE WORKPAPERS"
       
        ChildDirectory = ParentDirectory & "\FY" & Format(Today, "YYYY") & " Financial Close Workbook"
        
        MonthlyDirectory = ChildDirectory & "\FY" & Format(Today, "yymm") & "_" & Format(Today, "mmm")
        
        PrevMonthDate = WorksheetFunction.EoMonth((Now() - 1), -1)
    'MsgBox Format(PrevMonthDate, "MM/DD/YYYY")
        PrevMonthChildDirectory = ParentDirectory & "\FY" & Format(PrevMonthDate, "yyyy") & " Financial Close Workbook"
    'MsgBox PrevMonthChildDirectory
        PrevMonthlyDirectory = PrevMonthChildDirectory & "\FY" & Format(PrevMonthDate, "yymm") & "_" & Format(PrevMonthDate, "mmm")
        
    'MsgBox PrevMonthlyDirectory
    'MsgBox MonthlyDirectory
        
        FromPath = PrevMonthlyDirectory  '<< Change
    'MsgBox FromPath
        topath = MonthlyDirectory    '<< Change
        
        If Right(FromPath, 1) <> "\" Then
            FromPath = FromPath & "\"
        End If ' CLOSES IF FROM PATH
    
        If Right(topath, 1) <> "\" Then
            topath = topath & "\"
        End If ' CLOSES IF RIGHT TO PATH
    
        Set fso = CreateObject("scripting.filesystemobject")
    
        If fso.FOLDEREXISTS(FromPath) = False Then
            'MsgBox FromPath & " doesn't exist"
            Exit Sub
        End If ' CLOSES IF FSO.FOLDEREXISTS (FROM PATH)
    
        If fso.FOLDEREXISTS(topath) = False Then
            'MsgBox ToPath & " doesn't exist"
            Exit Sub
        End If ' CLOSES IF FSO.FOLDER (TOPATH) EXISTS
    
        For Each FileInFromFolder In fso.GetFolder(FromPath).files
                FileInFromFolder.COPY topath
            'End If ' CLOSES IF FDATE
        Next FileInFromFolder
    End Sub
    
    
    

    Friday, September 19, 2014 2:26 PM
  • >     Set fso = CreateObject("scripting.filesystemobject")

    Why do you need to create an object multiple times?

    Did you try to debug the code? What line of code generates an error?

    It looks like the issue is not related to Outlook at all. I'd suggest asking such questions on the The Official Scripting Guys Forum!  forum instead.

    Friday, September 19, 2014 6:52 PM
  • I'd have to agree with Eugene, it's not really Outlook related aside from running the VBA code in the Outlook VBA project.

    I'd set a breakpoint on the Err object <> 0 and see exactly what's going on. I'd also switch the for...each loop into an enumerated loop and release the File object in each loop pass by setting it to Nothing.


    Ken Slovak MVP - Outlook

    Friday, September 19, 2014 8:41 PM
    Moderator