+ Reply to Thread
Results 1 to 3 of 3

Code returning error 400

Hybrid View

reggie1000 Code returning error 400 03-09-2009, 01:23 PM
Tarball Re: Code returning error 400 03-09-2009, 01:30 PM
reggie1000 Re: Code returning error 400 03-10-2009, 05:53 AM
  1. #1
    Forum Contributor
    Join Date
    11-23-2007
    Location
    Suffolk, UK
    Posts
    298

    Code returning error 400

    Hello,

    I have the following code that opens a series of workbooks on a given day, however, if one of the workbooks has been renamed or is missing the code gives a "400" error and stops, is there a way of having the code retry the next workbook if it comes to an error?


    Sub Auto_Open()
       Columns("P:AI").Select
        Selection.EntireColumn.Hidden = False
        ActiveWindow.SmallScroll Down:=39
        Range("B62").Select
    Workbooks.Open Filename:="F:\DAILY FIGURES\DAILY FIGS 2009\" & Cells(2, 27) & "\" & Cells(3, 27) & ".xls"
     Workbooks.Open ("F:\Load List\P1 " & Cells(2, 20) & ".xls")
      Workbooks.Open ("F:\Load List\P3 " & Cells(2, 20) & ".xls")
      Workbooks.Open ("F:\Load List\RC " & Cells(2, 20) & ".xls")
      Workbooks.Open ("F:\Load List\P3 " & Cells(33, 20) & ".xls")
      Workbooks.Open ("F:\Load List\RC " & Cells(33, 20) & ".xls")
      Workbooks.Open ("F:\Load List\P1 " & Cells(33, 20) & ".xls")
      Workbooks.Open ("F:\Load List\P2 " & Cells(33, 20) & ".xls")
      Workbooks.Open ("F:\Load List\P2 " & Cells(2, 20) & ".xls")
      End Sub
    Many thanks in advance reg
    Last edited by reggie1000; 03-10-2009 at 05:54 AM.

  2. #2
    Forum Contributor Tarball's Avatar
    Join Date
    04-21-2007
    Location
    Atlanta, GA
    Posts
    166

    Re: Code returning error 400

    Add in the line On Error Resume Next

    This is not the best way to code but it will solve your issue. Instead you should think about configuring a way to change the name. One way I have done this is to have a configuration workbook that allows me to use a command button to locate files I want to open. Use the configuration workbook to then manage which workbooks get opened. In the event the workbook name changes you simply change the name accordingly in the configuration workbook

    Sub Auto_Open()
    
    On error resume next
       Columns("P:AI").Select
        Selection.EntireColumn.Hidden = False
        ActiveWindow.SmallScroll Down:=39
        Range("B62").Select
    Workbooks.Open Filename:="F:\DAILY FIGURES\DAILY FIGS 2009\" & Cells(2, 27) & "\" & Cells(3, 27) & ".xls"
     Workbooks.Open ("F:\Load List\P1 " & Cells(2, 20) & ".xls")
      Workbooks.Open ("F:\Load List\P3 " & Cells(2, 20) & ".xls")
      Workbooks.Open ("F:\Load List\RC " & Cells(2, 20) & ".xls")
      Workbooks.Open ("F:\Load List\P3 " & Cells(33, 20) & ".xls")
      Workbooks.Open ("F:\Load List\RC " & Cells(33, 20) & ".xls")
      Workbooks.Open ("F:\Load List\P1 " & Cells(33, 20) & ".xls")
      Workbooks.Open ("F:\Load List\P2 " & Cells(33, 20) & ".xls")
      Workbooks.Open ("F:\Load List\P2 " & Cells(2, 20) & ".xls")
      End Sub
    Reach me at excel_help at bellsouth dot net

  3. #3
    Forum Contributor
    Join Date
    11-23-2007
    Location
    Suffolk, UK
    Posts
    298

    Re: Code returning error 400

    Thanks Tarball,

    Its so simple and it works,

    thanks for the help

    Reg

+ 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