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! -
'Application.Run "INTRANET.XLSM!Revenue_Format"
-
-
Sub Revenue_Format()
-
-
areaCount = ActiveCell.CurrentRegion.Rows.Count
-
If areaCount < 1 Then
-
GoTo End_Format:
-
Else
-
GoTo Over_65000:
-
End If
-
-
Over_65000:
-
-
areaCount = ActiveCell.CurrentRegion.Rows.Count
-
If areaCount > 65500 Then
-
GoTo End_Format:
-
Else
-
GoTo Continue_Format:
-
End If
-
-
Continue_Format:
-
-
Range("H1").Select
-
ActiveCell.FormulaR1C1 = "Parent Principal"
-
-
Range("A1:L1").Select
-
With Selection.Borders(xlEdgeBottom)
-
.LineStyle = xlContinuous
-
.Weight = xlThin
-
.ColorIndex = xlAutomatic
-
End With
-
With Selection
-
.HorizontalAlignment = xlCenter
-
.VerticalAlignment = xlBottom
-
.WrapText = False
-
.Orientation = 0
-
.ShrinkToFit = False
-
.MergeCells = False
-
End With
-
Selection.Font.Bold = True
-
Columns("I:I").Select
-
Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""_);_(@_)"
-
Columns("A:A").Select
-
Selection.NumberFormat = "mmm-yy"
-
Cells.Select
-
Cells.EntireColumn.AutoFit
-
Range("A1").Select
-
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
-
ActiveCell.CurrentRegion, TableDestination:="", TableName:= _
-
"PivotTable1"
-
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:="Parent Principal", _
-
ColumnFields:="Period", PageFields:=Array("Region", "Market", "P&L", _
-
"Branch Name", "Account", "Principal", "Customer Name", "Division", "Category")
-
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Amount")
-
.Orientation = xlDataField
-
.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""_);_(@_)"
-
End With
-
Range("A10").Select
-
ActiveSheet.PivotTables("PivotTable1").PivotFields("Data").PivotItems( _
-
"Sum of Amount").Name = "Revenue Report"
-
Range("C1").Select
-
Selection.EntireRow.Insert
-
Range("A1").Select
-
-
Application.Run "INTRANET.XLSM!Delete_Data"
-
-
ActiveWorkbook.Save
-
ActiveWindow.Close
-
-
End_Format:
-
-
End Sub
-
21 6477
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.
NeoPa 32,556
Expert Mod 16PB
With 72 lines of code you will need to specify which of them the error occurs on.
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!
If you use error handling in all your code, you can catch these errors and give a helpful message box rather than crashing. - On Error GoTo ErrorHandler
-
-
'code
-
-
ExitCode:
-
Exit Function
-
-
ErrorHandler:
-
MsgBox Err.number & " " & Err.Description
-
Resume ExitCode
It fails at line 59
ActiveSheet.PivotTables("PivotTable1").PivotFields ("Data").PivotItems( _
"Sum of Amount").Name = "Revenue Report"
??
Maybe you can get a more specific error with the message box.
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.
Message box gives me 0...
Used Option Explicit and compiled. Nothing.
NeoPa 32,556
Expert Mod 16PB @newnewbie
What happened when you traced through the code?
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".
[IMG]C:\Documents and Settings\lskalska\Desktop\Error.xlsx[/IMG]
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.
[IMG]C:\Documents and Settings\lskalska\Desktop\Error.jpg[/IMG]
[IMG]C:\Documents and Settings\lskalska\Desktop\error2.jpg[/IMG]
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 :)
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!
Glad to hear you figured it out. I'm sure other people will have the same problem, and your solution will help them.
Now I know how to use the errorhandler :)
Thanks!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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"...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |