+ Reply to Thread
Results 1 to 5 of 5

error file cannot be found

Hybrid View

Aquila error file cannot be found 02-09-2010, 11:19 PM
shg Re: error file cannot be found 02-10-2010, 12:08 AM
Aquila Re: error file cannot be found 02-10-2010, 01:37 AM
shg Re: error file cannot be found 02-10-2010, 01:43 AM
Aquila Re: error file cannot be found 02-10-2010, 04:18 PM
  1. #1
    Registered User
    Join Date
    02-09-2010
    Location
    brussels
    MS-Off Ver
    Excel 2003
    Posts
    63

    error file cannot be found

    Hello,

    With this macro i print nine sheets. If there is one missing, excel gives a warning that the document cannot be found. I want excel to go ahead with the following document. Can somebody help me out please.

    Sub printenN()
    
        ChDir "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\20"
        
        Application.EnableEvents = False
        Workbooks.Open Filename:= _
            "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\20\20_" & Format(Date - 1, "dd-mm-yyyy") & "E.xls" '_
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
        ActiveWorkbook.Close False
        
        ChDir "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\21"
        
        Application.EnableEvents = False
        Workbooks.Open Filename:= _
            "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\21\21_" & Format(Date - 1, "dd-mm-yyyy") & "E.xls" '_
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
        ActiveWorkbook.Close False
        
        ChDir "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\22"
        
        Application.EnableEvents = False
        Workbooks.Open Filename:= _
            "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\22\22_" & Format(Date-1, "dd-mm-yyyy") & "E.xls" '_
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
        ActiveWorkbook.Close False
        
        ChDir "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\50"
        
        Application.EnableEvents = False
        Workbooks.Open Filename:= _
            "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\50\50_" & Format(Date - 1, "dd-mm-yyyy") & "E.xls" '_
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
        ActiveWorkbook.Close False
        
        ChDir "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\51"
        
        Application.EnableEvents = False
        Workbooks.Open Filename:= _
            "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\51\51_" & Format(Date - 1, "dd-mm-yyyy") & "E.xls" '_
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
        ActiveWorkbook.Close False
        
        ChDir "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\52"
        
        Application.EnableEvents = False
        Workbooks.Open Filename:= _
            "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\52\52_" & Format(Date - 1, "dd-mm-yyyy") & "E.xls" '_
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
        ActiveWorkbook.Close False
        
        ChDir "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\53"
        
        Application.EnableEvents = False
        Workbooks.Open Filename:= _
            "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\53\53_" & Format(Date - 1, "dd-mm-yyyy") & "E.xls" '_
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
        ActiveWorkbook.Close False
        
        ChDir "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\54"
        
        Application.EnableEvents = False
        Workbooks.Open Filename:= _
            "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\54\54_" & Format(Date - 1, "dd-mm-yyyy") & "E.xls" '_
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
        ActiveWorkbook.Close False
        
        ChDir "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\55"
        
        Application.EnableEvents = False
        Workbooks.Open Filename:= _
            "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\55\55_" & Format(Date - 1, "dd-mm-yyyy") & "E.xls" '_
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
        ActiveWorkbook.Close False
        
    End Sub

    many thanx
    Last edited by Aquila; 02-10-2010 at 06:33 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: error file cannot be found

    Welcome to the forum.

    Try this (untested):
    Sub printenN()
        Const sRoot     As String = "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\"
        Dim sFile       As String
        Dim v           As Variant
    
        On Error Resume Next
        Application.EnableEvents = False
        
        For Each v In Array("20\20", "21\21", "22\22", "50\50", "51\51", "52\52", "53\53", "54\54", "55\55")
            sFile = v & Format(Date - 1, "_dd-mm-yyyy") & "E.xls"
            Debug.Print sRoot & sFile
            Workbooks.Open sRoot & sFile
            ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
            ActiveWorkbook.Close False
        Next v
        
        Application.EnableEvents = True
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    02-09-2010
    Location
    brussels
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: error file cannot be found

    Hello,

    Thanks for welcoming me shg.

    I've tried this out and have no sheet in folder 22. Printing stops after printing the document in folder 21, prints the first sheet in the map where this macro is and stops then.
    Help is welcome ;-)

    greetz
    Aquila

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: error file cannot be found

    I have no convenient way to test ...
    Sub printenN()
        Const sRoot     As String = "N:\Oper_CT_PlantMgt\Shared\Hartslagborden met SI\Archief HBB\"
        Dim sFile       As String
        Dim v           As Variant
    
        Application.EnableEvents = False
    
        For Each v In Array("20\20", "21\21", "22\22", "50\50", "51\51", "52\52", "53\53", "54\54", "55\55")
            sFile = v & Format(Date - 1, "_dd-mm-yyyy") & "E.xls"
            Debug.Print sRoot & sFile
            If Len(Dir(sRoot & sFile)) Then
                Workbooks.Open sRoot & sFile
                ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
                ActiveWorkbook.Close False
            End If
        Next v
    
        Application.EnableEvents = True
    End Sub

  5. #5
    Registered User
    Join Date
    02-09-2010
    Location
    brussels
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: error file cannot be found

    shg,

    Last code works fine! ;-) Solved!
    Thank you for good help.

    greets
    Aquila

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1