Free Microsoft Excel 2013 Quick Reference

Visual basic 400 error Results

Every time I load excel I get this Visual Basic 400 error. I am also getting
an error of Graph control. Failed to open graphics server?

Are these excel VB problems or is it something to do with my software I am

I have numerous excel add-ins etc that I use in data anlaysis and simulation.


When I use tools | references to set a reference to an add-in, I get a
dialog box captioned "Microsoft Visual Basic" with the message "400". Can
someone tell me the meaning and possible steps needed to correct the



Hello, Im running a macro and I get a mesage:

Microsoft Visual Basic:
X 400
Accept / Help

I click help and I get nothing... does anyone know what it is about?


I have attached sample files of what I am running. Please forgive me if my lingo is off but what I am trying to accomplish is I have an Excel template of a packing slip called Factory Master Packing Slip and it has an Import button. Once the import button is press it brings up a Import File box. You then select the file to import.. and this case it will be the Shipping Slip 2 file attached. It should take the data from form 1 to form 2. I have run this macro on other forms with luck but not with this one. Can the pros take a look at this and tell me what i am doing wrong. Maybe a setting?

Should state that I am getting the "400" error when running...

Anyone ever hear of this error before?

I have a print macro that now only works if sheet is unprotected.

Is there a macro that I could program that would unprotect and re protect at end with the password in the macro?


Sorry for sketchy info, but this is a student's laptop not available to me at
the moment;

Office 2003, up to date
WinXP up to date
Dell LT

On launch, XL loads as normal but always produces a small error msgbox
containing "Microsoft Visual Basic" in it's title bar. The content of the
message is simply the number 400 along with the red circle/white X, and
buttons labeled "Help" & "OK". The Help button launches a totally empty help
window regardless of internet connection or not. OK dismisses the msgbox & XL
seems to run fine at that point. Can even launch VB with no problem.

Issue is more of a nuisance than anything else, but would appreciate any
insights as to what is triggering the msgbox & how to correct it.

User has reinstalled Office with no change in behavior. No other Office apps
produce the msgbox.

Thanks for your thoughts |:>)

I am using Excel 2003 and VB for Applications to write a program to keep
track of our orders and inventory

no major problems until now....

i have a decent ammount of debugging experience so tracking down problems is
not too hard (usually....)

I have the following code in a sub, and it is the ONLY code in this
particular sub

private sub DoesWOExist()
' msgbox("got to a")
Sheets("customer orders").Select
' msgbox("got to b")
' msgbox("got to c")
Do While ActiveCell.Value <> ""
' msgbox(got to d")
If ActiveCell.Value = workOrderNumber Then
woExist = True
ActiveCell.Offset(1, 0).Select
End If

end sub

i have tried breakpoints and stepping and also the (commented) msgbox to try
and figure out WHAT is causing the error.

when the code is run, (and the msgbox lines are un-commented) i DO get the
got to a
got to b

then I get Microsoft Visual Basic popup window with a Red X and the message
"400". (wthout quotes), and an OK and HELP button. Nothing else. The HELP
button brings up an empty help window.

Range("d9") is empty (this error occurs even with something in that box - or
even with data in D10, D11, D12, etc)

I have looked for help on this error and haven't found anything yet.

My questions are

a) What is the '400' error
and more importantly
b) Why is it giving me that error? - I have used this same code before and
it worked.

Thanks in advance.

I get an error Visual Basic "400" message when this code is ran:

Sub DeleteSheets()
Dim wks As Worksheet

Application.DisplayAlerts = False
For Each wks In Worksheets
If InStr("Bill (", wks.Name) > 0 Then wks.Delete
Next wks

Application.DisplayAlerts = True

End Sub

How can I fix this?

Thank you,

I am trying to run a macro and i got the following message:
Microsoft Visual Basic: 400

What does that mean?

Also, I have the following line in my code:
Set rgSource = ThisWorkbook.Sheets("SG_WarrantRic").Range("ric_table")

how do i find where "ric_table" is? is there a way to search for it? please let me know. Thanks.


This subroutine (shown below) should be easy!

I am trying to copy a selected 14 column range from one tab (Break out) to another (Sort) when there is a value in Breakout's column 49. I am getting a Microsoft Visual Basic interrupt showing an X with 400. I know from testing that the interrupt happens at the line that reads:

Range("A" & sortIndex & ":N" & sortIndex).Select. 
This Is a syntax I 've used successfully before. Does anyone see the problem?
Sub move_brekout_to_sort() 
    rwIndex = 1 
    sortIndex = 1 
    Worksheets("Break out").Select 
    Sheets("Break out").Select 
    Do Until Cells(rwIndex, 48).Value = "" 
        If Cells(rwIndex, 49).Value  "" Then 
            Range("AW" & rwIndex & ":BJ" & rwIndex).Select 
            Range("A" & sortIndex & ":N" & sortIndex).Select 
            sortIndex = sortIndex + 1 
            Sheets("Break out").Select 
        End If 
        rwIndex = rwIndex + 1 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines

Hey everyone,

I've been developing an application in VBA to screen scrape a PCOMM Workstation Emulator for an IBM AS/400. The application stores the data in an array, then uses ADO to insert the code into the workbook, and pull the data back into a userform for manipulation. During development I wasn't having any errors until I received an 'Out of Memory' error which I attributed to the copious amount of controls that the userform was generating (controls are added programmatically as needed based on records retrieved from the Excel file). Therefore, I changed the userform exit method from Me.Hide to Unload Me. However, since then I have been experiencing issues with Excel crashing while the code was executing. The crashes are intermittent, and much more rare when stepping through the code, making it hard to identify the line of code causing the crash. Furthermore, the crashes sometimes occurred during the screen scrape and sometimes during the creation of the userform. I would sometimes receive an 'Automation Error' pop up, but it didn't highlight a specific line or provide much help. Most recently the crashes have started occurring after I close Excel and the window disappears, but before the task ends inside the task manager. Another interesting note is that if I run the add-in several times from the custom menu bar I have created multiple instances of the workbook show up in the VBE. I thought this might be related to the ADO query, but I'm not sure? At one point I was stepping through the code and it crashed on a reference to a function stored in my add-in module. The function sorted the array alphabetically. I thought maybe the call to that function was causing the crashes, so I rewrote the code inside my macro and removed the reference.

Troubleshooting steps so far:
-Reset all variables at the end of subroutines to free up memory.
-Defined each variable type, reducing the amount of variants to the bare minimum.
-Exported/Imported all modules and userforms to a blank workbook.
-Removed unneccesary PCOMM references
-Excluded code from add-in module (re-wrote code directly into the macro's modules)
-Copied/Pasted all code from modules and userform into a blank workbook.
-Tried both Me.Hide and Unload Me to hide the userforms.
-Tried moving all of the code from the four separate modules into one module.
-Tried stepping through the code (this rarely throws any errors for me)
-Tried removing all 'Call' functions; replaced with the function name and arguments
-Tried adding Option Explicit to the beginning of each module
-Tried running the macro and several machines
-Tried running automatic updates to get new office patches
-Tried updating functions to pass arguments ByVal and defined argument data types and function return value data types
-Tried commenting out various pieces of code in my main sub routine to identify what point errors started occurring.
-Tried cussing at it until it worked.

References I am using:
-Visual Basic For Applications
-Microsoft Excel 12.0 Object Library
-OLE Automation
-Microsoft Office 12.0 Object Library
-Microsoft Forms 2.0 Object Library
-Microsoft ActiveX Data Objects 2.8 Library
-Microsoft ActiveX Data Objects Recordset 2.8 Library
-PCOMM autECLOIA Automation Object 1.0 Library
-PCOMM autECLPS Automation Object 1.0 Library
-PCOMM autECLSession Automation Object 1.0 Library
-BCUtilities (Excel Add-in containing frequently used code)

A concern that I have now is that after all of my troubleshooting I've fixed one crashing error, but gained another. As I said, the crashes seem to have started occurring more after I close Excel than during the actual execution of the code, but being intermittent it is hard to judge. I also have to wait for a user to become available to run another test to see how their machine is responding after my troubleshooting attempts.

I hate to post the code because there's a lot of it, and also because I have some security concerns, but if it is necessary I can probably do it (as a whole, in chunks, or as an attachment, I'm not sure what the preferred method is here?)

So, I suppose this is what I'm curious about:
-Why would multiple workbooks with the same name be opening when I rerun the macro? Could this cause Excel to crash when it closes?
-Is there some way to retrieve information about the crash after it occurs? I've tried looking at the report and the event log, but they're Greek to me.
-Can 'Out of Memory' errors cause corruption, and could I be inadvertently carrying that corruption to my new workbooks? Or perhaps my add-in was corrupted?
-Are there any known issues with the references I have that could cause an instability?
-Any other ideas?

Thanks in advance for any assistance. Please let me know if I can provide more information.

Windows XP Professional SP2
Microsoft Office 2007 and 2003
Dell Optiplex 745


Below is my macros for my project..

It works just fine..

But when i go back and protect the sheet...

It gives me an error message..

Can you help?

Sub mon()

j = Sheets("A-sites").Range("L17:p20").Value 'A Opening Inv,Receipts,Issues,Closing

Select Case Sheets("Monthly").Range("D20").Value

Case 1
Sheets("Monthly").Range("J24:N27").Value = j 'A Opening Inv,Receipts,Issues,Closing

Case 2
Sheets("Monthly").Range("O24:S27").Value = j 'A Opening Inv,Receipts,Issues,Closing

Case 3
Sheets("Monthly").Range("T24:X27").Value = j 'A Opening Inv,Receipts,Issues,Closing

Case 4
Sheets("Monthly").Range("Y24:AC27").Value = j 'A Opening Inv,Receipts,Issues,Closing
End Select

End Sub


When I try to run the following code in a macro:

Sub PrintToAnotherPrinter()

Dim STDprinter As String

STDprinter = Application.ActivePrinter

Application.ActivePrinter = "Adobe PDF on Ne02"

End Sub

I am getting an error code that looks like this:

Microsoft Visual Basic
Red Cross "400"
OK Help

Help brings up a blank screen and OK just cancels the operation. Can anyone help me with my code?


I have installed an Add-In from for MS Excel with the name 'Simple Excel Shortcuts'. The installation file has an .xla file as add-in.

I installed the same. But when I open the MS Excel and clicking on the 'Data' tab immediately an error message with 'Microsoft Visual Basic' with a white 'X' symbol inside a red circle showing error number 400 with two options below 'OK' and 'Cancel'. If I click on 'OK' the dialog box is being closed and no problem further.

If I close Excel and re-open it again same thing is occurring.

I tried for the system restore option, but it was not having any restore point before this add-on was installed. I tried to repair Office but it came that it can't be repaired.

After that I tried to uninstall the whole Microsoft Office 2007 and reinstall it. But after so much time of displaying that boring MS logo, it was giving a dialog box with 'Microsoft Office Enterprise 2007 could not be unistalled due to some system errors. Please try again later.'

How can I get rid of this annoying 400 error. Please help me friends... :-(

As soon as I found the error immediately I deleted the .xla file and it's corresponding folder. Still it is coming. I have opened the VBA editor but there it is showing nothing I mean no code or that sort of thing. It is blank.

I restored to the very very long dated System Restore point. All my softwares were gone of course I can reinstall them. But the problem still persists. :-(

The add-in is not visible, as I searched for it in the Excel> Options > Add-Ins. There I found only the in-bulit add-ins but not this one. I tried to uninstall MS Office but it is showing unsuccessful. I am really got vexed with this. It is neither getting uninstalled not showing the installed add-in. How to remove this is only my concern. Please don't suggest Formatting!

To make the discussion specific to the point, I would like to give the exact phrases that were appearing on the uninstllation screen.

They were 'Microsoft Office Enterprise 2007 did not uninstall successfully'.

Only this one line was being displayed with a 'OK' button.


P.S. I got a great lesson that never try any Add-on if you are not sure about how is it going to mess you up or how can you get rid of that mess if it messes you!

Hi all,

I have a couple of problems that I cant seem to fix!

Firstly - The following code copies and sends an excel spreadsheet file (containing 3 sheets). The code seems to works on some computers and not on others and I’m getting an error message box (Microsoft Visual Basic with a red circle and a cross in it, and the number 400). The worksheets are protected could this be a contributing factor? (they need to remain protected) I should prolly also mention that the file is sent and recieved between two types of email applications (a government based email platform and outlook).

Secondly - Recent testing of the code has produced a small problem for the email receiver - when the file is opened they’re prompted with a message box to ‘update or not update links’ (an oversight on my behalf - I should have mentioned this to Leith when he wrote the code for me)…. But can a line of code be added asking it ‘not to update’ so the pop up will not occur, or would a paste special (values) be the way to go? I’m new to VBA so I’m not sure how to write this in.

Can anyone help me with these issues? – code below

Sub CustomEmail3Sheets()
  Dim Wks As Worksheet
  Dim Wkb As Workbook
  Dim WkbName As String
   'Create a new workbook with 1 sheet
    Set Wkb = Workbooks.Add(xlWBATWorksheet)
   'Rename the sheet as space to prevent sheet naming conflicts
    Wkb.Worksheets(1).Name = " "
     'Add the custom sheet named to the new workbook
      For Each Wks In ThisWorkbook.Worksheets
        Select Case Wks.Name
          Case Is = "Sheet name 1", "Sheet name 2", "Sheet name 3"
            Wks.Copy After:=Wkb.Worksheets(Wkb.Worksheets.Count)
        End Select
      Next Wks
       'Delete the original sheet and save the workbook
        Application.DisplayAlerts = False
          Wkb.SaveAs "Copy of " & ThisWorkbook.Name
        Application.DisplayAlerts = True
       'Email the workbook
        Application.Dialogs(xlDialogSendMail).Show Arg2:=Wkb.Name
     'Save the path to the new workbook and close it
      WkbName = Wkb.FullName
   'Delete the new workbook
    Kill WkbName
End Sub

The following code has been used successfully in Excel 2000 for several
years. My company is beginning to transition users to Excel 2003 and
users are calling me to fix errors on several parts of my code. Here
is one example:

With Sheets(datasheet).Range("A1").CurrentRegion
.Offset(, (ReportDataToUseColumnArray(x,
ReportDataColumnInDb)) - 1).Resize(, 1).Copy _
Sheets("Report").Range(startCell).Offset(, x -
End With

The message is visual basic error #400

To solve the problem, I added some error code "Resume Next" and the
macro runs just fine. Everything that is supposed to be copied, copies
just fine, but without the "Resume Next" the code errors out.

any suggestions?

This macros just received works but does not seem to stop
the looping until it returs the error "MS Visual Basic
I would appreciate a bit of tweaking.

i = 1
Target = Range("D" & i)
TargetLength = Len(Target)
CharLeft = Left(Target, 1)
CharRight = Right(Target, 1)

If CharLeft = ";" Then Target = Right(Target, Len
(Target) - 1)
If CharRight = ";" Then Target = Left(Target, Len
(Target) - 1)

Range("D" & i) = Target
i = i + 1

I have a workbook designed in Excel 2003. The worksheets are used to score newsletters entered in a contest. I have two work sheets:

1. Awards - This sheet lists the newsletters entered in the contest, the name of the club and the frequency of publication.

2. Template - This sheet is the actual score sheet.

I have it set up so that the individual club tabs are automatically generated and the information on Awards is copied the appropriate spot on the club's score sheet. All was working well until I added a splash screen. Now, it will create the 1st sheet, and then I get error 400.

I also wanted to add the feature that if the frequency field on the Awards sheet is blank, a message box will appear to tell you to fill in the required data before proceeding.

I am a novice with Visual Basic and would appreciate any help anyone could provide.

Thanks in advance.

I'm trying to set a reference to my personal file (VBE TOOLS>REFERENCES). I keep getting a message box with a title "Microsoft Visual Basic", an "X" inside a red circle (critical) and "400" as the message, with "OK" and "Help" buttons. I click "Help" and get no help, just the "getting started" screen of help. I click "OK" and the reference is not set.

I have had no problem setting the reference before.

I just discovered that macros were turned off in this file. I closed the file and reopened it with macros enabled and the Error (?) went away.

I have had this same message box before under different circumstances and was never able to discover what it meant or if it was causing any problems.

Can anyone enlighten me as to what "400" means?

In this solution I will show how we can connect Excel to a MS SQL Server-database and view the retrieved data in a pivottable on a userform.

The solution can easily be adapted with Visual Basic and Visual Basic.Net and also be applied with other databases like SyBase, DB2, Oracle, MySQL and MS Access as well with Excel-workbooks.

What we need:
MS Windows operating system (Windows 98 and above)
MS Excel 2000 or above
MS ADO 2.5 or above
MS Web Office Components (OWC)
(For Office 2002 and 2003 these are available at MS homepage for download while for 2000 these are shipped with the Office-CD)
MS SQL Server with the database Northwind

- Add a reference to the ADO-Library.

Create the Pivottable in the userform
1. Add the Active-X control “Microsoft Office Pivottable x.x” to the available controls.
2. Add a userform to the VBA-project.
3. Draw the Active-X control on the userform and set its height to approx 30 and width 400.
4. Add a Close-button to the userform and name it cmbClose.

Create following events-procedures in the userforms classmodule:

Private Sub cmbClose_Click() 
    Unload Me 
End Sub 
 'If we want to trace any error during the process of retrieving
 'data we can add the following event-procedure to
 'the userforms classmodule:
Private Sub PivotTable1_QueryComplete() 
End Sub 
Private Sub UserForm_Initialize() 
    Dim stConn As String, stSQL As String, stCaption As String 
     'Create the connectionstring
    stConn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data
     'Create the SQL-statement.
    stSQL = "SELECT ShipName, ShipCountry, ShipCity, Freight FROM ORDERS&" 
     'Create the caption for the pivottable.
    stCaption = "Using the Office Web Component Pivottable to retrieve and view data." 
    With Me.PivotTable1 
         'Prevent the control to occupy the whole space of the userform
        .AutoFit = False 
         'Hide the toolbar.
        .DisplayToolbar = False 
         'Add the connectionstring
        .ConnectionString = stConn 
         'Add the commandtext
        .CommandText = stSQL 
        With .ActiveView 
             'Use the standardlayout.
             'Add the caption of the Pivottable.
            .TitleBar.Caption = stCaption 
             'Add fields to the PAGE-area of the Pivottable.
            .FilterAxis.InsertFieldSet .FieldSets("ShipCountry") 
            .FilterAxis.InsertFieldSet .FieldSets("ShipCity") 
             'Add one field to the ROW-area of the Pivottable.
            .RowAxis.InsertFieldSet .FieldSets("ShipName") 
             'Add one computed field (Summing) to the DATA-area of the Pivottable.
            .DataAxis.InsertTotal .AddTotal("Total freight per Customer", .FieldSets("Freight").Fields(0),
             'If we would like to add fields to the COLUMN-area of the Pivottable we use
             '.ColumnAxis.InsertFieldSet .FieldSets("Name")
             'All records are in the startup-position collapsed.
            .FieldSets("ShipName").Fields(0).Expanded = False 
        End With 
         'View the available fields for the Pivottable. However in this sample we have
         'via the SELECT-statement limit the number of available fields to the Pivottable.
        .DisplayFieldList = True 
    End With 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
Remark: We can, of course, also add code for tracing ADO-errors. For an example see

Handling ADO-errors explicit

In a standardmodule insert following procedure and add a button into a worksheet.

Option Explicit

    UserForm1.Show vbModeless 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines

The Pivottable-component is a powerful control and in a coming solution I will show how we can connect to a cube and view parent-childdata in it. If possible use the latest version of the control.

A note is that it does not require lot of code for creating a solution with this component.

Kind regards,

No luck finding an answer? You could always try Google.