473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Excel 2003 VBA crashes Excel 2007?

newnewbie
Hi,
Our company recently transitioned to Office 2007 and one of my macros crashes Excel 2007 - gives "Excel encountered a serious error and needs to close" always at the same spot of the code. I combed the web to see if there are grave differences between VBA in 2003 and 2007 and found nothing...this is the code. I would appreciate any suggestions!

Expand|Select|Wrap|Line Numbers
  1. 'Application.Run "INTRANET.XLSM!Revenue_Format"
  2.  
  3. Sub Revenue_Format()
  4.  
  5.     areaCount = ActiveCell.CurrentRegion.Rows.Count
  6.     If areaCount < 1 Then
  7.         GoTo End_Format:
  8.     Else
  9.         GoTo Over_65000:
  10.     End If
  11.  
  12. Over_65000:
  13.  
  14.     areaCount = ActiveCell.CurrentRegion.Rows.Count
  15.     If areaCount > 65500 Then
  16.         GoTo End_Format:
  17.     Else
  18.         GoTo Continue_Format:
  19.     End If
  20.  
  21. Continue_Format:
  22.  
  23.     Range("H1").Select
  24.     ActiveCell.FormulaR1C1 = "Parent Principal"
  25.  
  26.     Range("A1:L1").Select
  27.     With Selection.Borders(xlEdgeBottom)
  28.         .LineStyle = xlContinuous
  29.         .Weight = xlThin
  30.         .ColorIndex = xlAutomatic
  31.     End With
  32.     With Selection
  33.         .HorizontalAlignment = xlCenter
  34.         .VerticalAlignment = xlBottom
  35.         .WrapText = False
  36.         .Orientation = 0
  37.         .ShrinkToFit = False
  38.         .MergeCells = False
  39.     End With
  40.     Selection.Font.Bold = True
  41.     Columns("I:I").Select
  42.     Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""_);_(@_)"
  43.     Columns("A:A").Select
  44.     Selection.NumberFormat = "mmm-yy"
  45.     Cells.Select
  46.     Cells.EntireColumn.AutoFit
  47.     Range("A1").Select
  48.     ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
  49.         ActiveCell.CurrentRegion, TableDestination:="", TableName:= _
  50.         "PivotTable1"
  51.     ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:="Parent Principal", _
  52.         ColumnFields:="Period", PageFields:=Array("Region", "Market", "P&L", _
  53.         "Branch Name", "Account", "Principal", "Customer Name", "Division", "Category")
  54.     With ActiveSheet.PivotTables("PivotTable1").PivotFields("Amount")
  55.         .Orientation = xlDataField
  56.         .NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""_);_(@_)"
  57.     End With
  58.     Range("A10").Select
  59.     ActiveSheet.PivotTables("PivotTable1").PivotFields("Data").PivotItems( _
  60.         "Sum of Amount").Name = "Revenue Report"
  61.     Range("C1").Select
  62.     Selection.EntireRow.Insert
  63.     Range("A1").Select
  64.  
  65.     Application.Run "INTRANET.XLSM!Delete_Data"
  66.  
  67.     ActiveWorkbook.Save
  68.     ActiveWindow.Close
  69.  
  70. End_Format:
  71.  
  72. End Sub
  73.  
Apr 1 '09 #1
21 6477
ChipR
1,287 Expert 1GB
You can put a breakpoint in at the top of the function and step through until you find an error, or you can put in error handling and give yourself a msgbox telling you what the error is.
Apr 2 '09 #2
NeoPa
32,556 Expert Mod 16PB
With 72 lines of code you will need to specify which of them the error occurs on.
Apr 2 '09 #3
NeoPa,
The problem is, I do not know. I do not get the VBA error, I get the "Excel encountered a serious error and needs to close". I suspect some part of the code that manipulates the pivottable is no longer valid, since there were sone significant changes to the pivottable format in the new Excel. I'll take ChipR advice, pull the code into a new test workbook and step through the code one line at a time until I find the error. I'll repost if I am still clueless :)
Thank you all!
Apr 2 '09 #4
ChipR
1,287 Expert 1GB
If you use error handling in all your code, you can catch these errors and give a helpful message box rather than crashing.

Expand|Select|Wrap|Line Numbers
  1. On Error GoTo ErrorHandler
  2.  
  3.     'code
  4.  
  5. ExitCode:
  6.     Exit Function
  7.  
  8. ErrorHandler:
  9.     MsgBox Err.number & " " & Err.Description
  10.     Resume ExitCode
Apr 2 '09 #5
I'll try that! Thanks!
Apr 2 '09 #6
It fails at line 59

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Data").PivotItems( _
"Sum of Amount").Name = "Revenue Report"

??
Apr 2 '09 #7
ChipR
1,287 Expert 1GB
Maybe you can get a more specific error with the message box.
Apr 2 '09 #8
NeoPa
32,556 Expert Mod 16PB
This link may help (Debugging in VBA).

If it doesn't include it already, remember to use Option Explicit and to compile your project before proceeding to debug.
Apr 2 '09 #9
Message box gives me 0...
Apr 2 '09 #10
Used Option Explicit and compiled. Nothing.
Apr 2 '09 #11
NeoPa
32,556 Expert Mod 16PB
@newnewbie
What happened when you traced through the code?
Apr 2 '09 #12
ChipR
1,287 Expert 1GB
@newnewbie
What does this mean?
Apr 2 '09 #13
If the errorhandler code is in there, when I hit line59 of the code, it gives me the error message with single "0" in it and the code stops. If I take eerorhandler out, Excel crashes with the same "Excel encountered a serious error and needs to close".
Apr 2 '09 #14
[IMG]C:\Documents and Settings\lskalska\Desktop\Error.xlsx[/IMG]
Apr 2 '09 #15
ChipR
1,287 Expert 1GB
Strange, error 0 would actually mean no error. I haven't used pivot tables, so my only guess would be to make sure that "Data" and "Sum of Amount" do actually exist.
Apr 2 '09 #16
[IMG]C:\Documents and Settings\lskalska\Desktop\Error.jpg[/IMG]
Apr 2 '09 #17
[IMG]C:\Documents and Settings\lskalska\Desktop\error2.jpg[/IMG]
Apr 2 '09 #18
Ok, thank you everybody. I have until next Wed to resolve this or else I will have to format close to a hundred pivots by hand :)
Apr 2 '09 #19
I did it!
Old code line 59-60:
ActiveSheet.PivotTables("PivotTable1").PivotFields ("Data").PivotItems( _
"Sum of Amount").Name = "Revenue Report"

New code (changes in bold):

ActiveSheet.PivotTables("PivotTable1").DataPivotField.PivotItems("Sum of Amount").Caption = "Revenue Report"

THANK YOU ALL!
Apr 2 '09 #20
ChipR
1,287 Expert 1GB
Glad to hear you figured it out. I'm sure other people will have the same problem, and your solution will help them.
Apr 2 '09 #21
Now I know how to use the errorhandler :)
Thanks!
Apr 2 '09 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Inbox.Mirror.Orbisoft | last post by:
In the last 1-3 weeks, we have had numerous users of Task Manager 2007 (www.orbisoft.com) complain that they can no longer export certain reports (Task Manager 2007 uses a Sagekey.com Access 97...
0
by: Inbox.Mirror.Orbisoft | last post by:
In the last 1-3 weeks, we have had numerous users of Task Manager 2007 (www.orbisoft.com) complain that they can no longer export certain reports (Task Manager 2007 uses a Sagekey.com Access 97...
0
by: thought.contagion | last post by:
I need to determine if Excel 2007 is installed. For Office 2003, we had the component ID for Excel 2003 and could use the msi.dll to enumerate and that would tell us if it was installed: iRet...
0
by: Bill Fallon | last post by:
I am developing a VB.Net application with VS 2005 that opens an Excel workbook and populates the worksheet with data. I started developing the application with Office 2007 installed on my Vista...
0
by: silverear | last post by:
Hello everybody, I have written an application that is running as an Office project within Excel in C#. I created a setup project for my tool. When I install my program on a machine that has...
15
by: =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= | last post by:
Hi All, We are in the process of Upgrade Excel 2003 (Office 2003) to Excel 2007 (Office 2007) for one of web application. This web application is using Excel (Pivot Table) reports. With Excel...
0
by: Noob | last post by:
Hello, I created an ERP based custom report using Access '03 & Excel '03. I developed an Access query that pulls the required data from the ERP (Progress) database via link tables. I use Excel...
1
by: =?Utf-8?B?U3RlcGhhbmU=?= | last post by:
Hello I would like to know if it is possible to return to MS Excel 2003 after you have upgraded to MS Excel 2007? Here below is what occured. 1. I installed MS Office Home and Student 2007...
0
by: James Minns | last post by:
Hi all, I have a problem with Excel 2007: it crashes when importing certain xml data, exported from another software This is the smallest file which reproduces the problem: <?xml version="1.0"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.