Error Message that just says 400??

Cosmos75

Active Member
Joined
Feb 28, 2002
Messages
359
Code:
Sub PrintReport()

'Makes sure that the status bar is visible
Application.DisplayStatusBar = True

'Enter message for status bar
Application.StatusBar = "Generating Report!"

'Turn off Screen updating
Application.ScreenUpdating = False

Dim WS As Worksheet
Dim ReportMonth As String
Dim LHeader As String

ReportMonth = Sheets("Summary").Range("A3").Value
LHeader = Sheets("Comboboxes ").Range("B19").Value

For Each WS In Sheets

'If statement to exclude  certain worksheets
If WS.Name <> "Comboboxes" Then
    If WS.Name <> "Values" Then
        If WS.Name <> "Material" Then

' Enter your message for the statusbar:
  Application.StatusBar = "Formatting Report..."
    
    WS.Select
            
    With WS.PageSetup
        .LeftHeader = LHeader & Chr(13) & ReportMonth
        .CenterHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0.75)
        .RightMargin = Application.InchesToPoints(0.75)
        .TopMargin = Application.InchesToPoints(1)
        .BottomMargin = Application.InchesToPoints(1)
        .HeaderMargin = Application.InchesToPoints(0.5)
        .FooterMargin = Application.InchesToPoints(0.5)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .CenterHorizontally = True
        .CenterVertically = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
    
Select Case WS.Name

Case Is = "Normal"
WS.PageSetup.RightHeader = "Normal"

Case Is = "Abnormal"
WS.PageSetup.RightHeader = "Abnormal"

Case Is = "Summary"
WS.PageSetup.RightHeader = "Summary"

End Select
    
'    Enter your message for the statusbar:
    Application.StatusBar = "Previewing page.."
    
    ActiveWindow.SelectedSheets.PrintPreview

        End If
    End If
End If

Next WS
    
'Makes sure that the status bar is invisible
Application.DisplayStatusBar = False

'Turn on Screen updating
Application.ScreenUpdating = True



End Sub

This code works but when it's done running I get an error message box (with the vbCritical sign - looks like a stop sign with an X) and the only message is 400? No text or anything just that number, what's going on?
:-?

The StatusBar says "Formatting Report..." so that where it's stuck at, gith? But it's shown me all the sheets (with the exception of the three that I eliminated with the If statements). So it should be done, right? Unless it's still looking for another worksheet?? I've used similiar code before and never had this happen??
 

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.
Error 400 has happened to me when I am trying to perform an invalid Windows function. I would suggest you start from the bottom of your code, go up 3 lines, and add a Stop in your code (or a break) and see if you get the error. Continue doing this until you can identify a 3-line chunk of your code that is causing the problem. This will give you (and anyone else trying to read your code) a better idea where to look.
 
Upvote 0
Ran the code line by line and after it selected all the sheets, it kept on going. Gave me error 1004. So I checked to see if there were any hidden sheets, and there were. Deleting them solved the problem!

THANKS!
 
Upvote 0

Forum statistics

Threads
1,223,757
Messages
6,174,331
Members
452,555
Latest member
colc007

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