I've written a script that builds excel reports. These reports may include pivot tables. To refresh a pivot table on load, I added refreshOnLoad="1" parameter to pivotCacheDefinition1.xml file. It works good with only one minor thing that I do not like - when I open a report, excel asks me "do you want to replace the contents of the destination cells"? I press "ok" and it refreshes pivot tables. I do not like this pop-up window with this question, and I think it's obvious that if refreshOnLoad="1" is specified then contents should always be refreshed. So, my question is how to suppress this window from popping up?
EDIT
According to this thread:
Whenever Excel will find that the update of it will replace the content of any existing cell,it will warn you.It is important feature.
So, does it mean that Excel will always warn, when it sees that pivot table contents should be refreshed?
EDIT
It seems like my problem is similar to this one. However, I'm not using VB macros, I'm building my reports with some other programming language (which programmatically unzips xlsx file and deals with all those xml files inside).
EDIT
Well, I tried both Application.AlertBeforeOverwriting = False and Application.DisplayAlerts = False, but none of them works.
I haven't been able to reproduce the problem, so these are more suggestions than answers.
I think the commands you are trying are occurring too late - Excel needs to know "not to alert before overwriting" before it tries to refresh. If it refreshes on open, then you set the property, you have the wrong sequence of events.
Try:
Do NOT put refreshOnLoad="1" in your file.
Add the VBA routine Workbook_Open() to the workbook.
In the VBA routine, set the property Application.AlertBeforeOverwriting = False, then invoke the method PivotTable.Refresh.
This should resolve any "sequence of events" problems.
Related
I have created a macro-enabled template, which contains only a empty dataset sheet sourced to a number of pivot tables.
Every time I try to save the template proper, or even a new workbook based on the template, I get the error:
This workbook contains external data. Do you want Microsoft Excel to clear the data before saving the template, and then automatically refresh the data whenever the template is opened?
There are no connections in data>connections>connections.
Edit Links is grayed-out in data>connections.
I have downloaded and ran "https://www.manville.org.uk/software/findlink.htm" with no links found.
The only item in formulas>name manager the dataset table with no external link.
I have unchecked file>options>advanced>ask to update automatic links.
I have enabled all items in file>options>trust center>external content.
I can't find anything in my VBA code that would cause an error like this.
This error prompt haunts me. Why is it doing this?
Thanks for any answers.
You most likely have a formula in a cell or a define name that points to an external file. Do a search for "HTTP" in your workbook and review your define name.
As it turns out, it's just a source template thing. Once I open a new document from the template, that warning doesn't come up.
I have an Excel file that's linked to a SQL database view. The Excel file needs some monthly massaging that I am trying to do with a VBScript but this dialog box keeps coming up and interrupting my VBScript:
This workbook contains links to one or more external sources that could be unsafe.
If you trust the links, update them to get the latest data. Otherwise, you can keep working with the data you have.
And buttons for Update, Don't Update and Help
I do trust the data (it's our on-site SQL server), I don't want to refresh the data with this specific script (it takes about 15 minutes and it is refreshed via another process). But the dialog box is holding up my whole VBScript, how do I dismiss it? I've tried ExcelObj.DisplayAlerts = False and ExcelObj.EnableEvents = False but neither is making this dialog box go away. Please help!
I am getting an error when opening excel: We found a problem with some content in XXX. Do you want us to try and recover as much as we can? if you trust he source of this workbook, click Yes."
clicking Yes, "fixes" the issue but deletes a lot of VBA code, two weeks worth.
Whatever the issue it was introduced yesterday, I do not want to redo two weeks worth of coding. Is there anyway I can view what was removed, or open the VBA in notepad++ or something without opening the excel?
I opened another excel workbook and tried all the different options for the argument XlCorruptLoad in the Workbooks.Open to open the corrupt workbook. I noticed that there were two non existing sheets created in the project explroer of the corrupt workbook that had the code in there. I am not sure if it did that s a result of what I did or it was there all along and I did not notice it
Note that the reason I had a corrupted data is because the code was extracting a list and putting it in a cell validation formula..i guess I overloaded it.
I'm almost sure I will have to create a new excel file, but maybe at least here I get some ideas what was the source of the problem.
My excel file is constantly giving the following error:
Excel found unreadable content in 'filename.xlsm'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.
So I do. And the file opens as repaired showing:
Removed Records: Sorting from /xl/worksheets/sheet10.xml part.
The detail is that I don't even have a sheet10
Its a big excel file full of custom-objects. But I have no DB connections or autofilter so could not relate to AutoFilter Criteria Using Array (Error) - Too Large String? or xlsx error: "Removed Records: Named range from /xl/workbook.xml part" when tried to resolve errors.
Anyone has a clue what's going on?
tks in advance
try clearing the sort before saving down the workbook. When this happened to me I had my sheet references mixed up so the sort wasn't cleared
Sheets(yoursheetname).Sort.SortFields.Clear
I am afraid I cannot explain what is going on, but I had similar experience several times - always with XLSM file. In the latest case I learnt that Excel did not like the same range name used twice, when defined as Worksheet range name (we assumed it is safe to use it that way).
Our troubleshooting path is:
try to save file as XLSB (binary macro file) and either use XLSB file or save it back to XLSM
check file history (we always keep daily snapshots) and find when the problem firstly occurred; use previous version and port your changes
extract the code (via SVN code), create a new workbook and import the code back
Usually Step 1 solves the problem, but Step 3 never failed us.
Awesome,
This issue has been driving me crazy!
It seems that saving as the xlsb (binary) file PLUS adding the clearing of sort fields appears to have sorted out my issue.
I added the following code to the BeforeClose sub, it appears to clear the fields really quick, changes to my Dashboard and prompts for saving.
The xlsb file saved over a mb in file size and appears to load a little quicker!
Thanks for the pointers & support!
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Sht As Worksheet
' Clear all Sort Fields prior to Save & Exit
For Each Sht In Application.Worksheets
Sht.Sort.SortFields.Clear
Next Sht
aa1_Dashboard1.Select
aa1_Dashboard1.Activate
End Sub
I would like to add my own confirmation regarding clearing sort fields in your spreadsheet, as first suggested by Chris. I specifically had the error occur after I used column sorting in a VBA macro, so I deduced that the problem must be column/field-Sort related. It was.
Adding the line:
Sheets(yoursheetname).Sort.SortFields.Clear
after the sort command allowed the sorted columns to remain sorted (in my case), but cleared whatever was causing the
"Sorting from /xl/worksheets/sheet10.xml part." error when the file was next opened.
Many thanks for your support.
I don't know if this will help anyone but it's solved my problem. I had an excel sheet, nothing complex, just contacts, a much used file in Excel 2010 on Win7. Today I was using the 'filter' to select specific groups to email targeted content to. In the middle of selecting and copying to paste into Outlook, the document came up with a pop up as if I was installing something, then the 'installer' both of which I cancelled out of. The Document closed and then on trying to reopen, I was getting the error message. If I chose 'yes' to repair I was given just the subset of my filtered list, so about 40 of my 350 records, the rest lost. I googled and tried different things, including opening in Googledocs google sheets and nothing worked. I never 'saved' the repaired version as my old data wasn't in that. Just now, I right clicked on my document in explorer and chose "restore previous versions" and it brought me to the version of yesterday - thankfully, nothing added to it since then. Opened that one and bingo, it opened fine with ALL the data in it. I know the filter had corrupted it, so will be cautious next time I use it. I don't know why it doesn't like the filter but 4 hours on, i can now calm down and relax! Hope this helps someone.
was having this issue as well. I have a spreadsheet with multiple tabs (maybe 30 tabs?) and had filters on each sheet, and shared on SharedPoint. The error was not enabling editing of the file on SharePoint. I removed the filters on every sheet and uploaded back to SharePoint and the issue is gone!
I did what Chris mentioned above. Clear the sort fields in your spreadsheet.
Sheets(yoursheetname).Sort.SortFields.Clear
Also, save the file as *.xlsb.
That should get it to work.
When you get a message telling that Excel found unreadable.... just click "Open" and then close all the following messages you get.
-In the VBE open the project showing the name of Addin or the .xlsm.. the click anywhere in any module of the workbook as you are going to edit the text of the macro, then click save, select workbook type like Addin select the folder where you want to save it, give it a new name then click "Save", that is all you have to do, the new file you created will ok.
Current Excel Report is created using Jasper Server / Jasper Report 3.8.
In my case , I would like to create Pivot Excel automatically using Excel(Since Jasper Report Crosstab is not sufficient for my client requirement), so i have an idea to add VB Script that will create Pivot Table when the generated jasper report is opened for first time.
I have created the VBA script However I couldn`t find a way to integrate the VBA with Jasper Report (generated) so that when I generated the Report, the VBA is also included in the Report.
Could anyone tell me how to to add VB Excel Script in Excel Generated Jasper Report?
Added Constraint:
List item
The Data Source (Excel File Containing Data) is protected
I know the question has been answered and accepted, but I just cannot resist to add a thought .....
Could it be that this question is asking to put the cart in front of the horse?
You create an Excel File REP using a report generator. Then you want to use this data as the source of an Excel Pivot table. As I see it there are a couple of possibilities to do that:
Create another Excel file PIV containing a structure of REP with some sample data to create the Pivot definitions
Copy / Paste the REP data replacing the existing content each time you draw a new REP
refresh the Pivot
This can be automated in PIV, asking for the source file name etc., so there is actually no need to touch REP in any way. As an alternative to copy / paste you can just use an external link to REP when you specify the data source for the pivot table, and change this every time the user wants to analyze a new REP.
Hope this helps
I think MikeD has the right idea here. I've never used Jasper, but if it's a CSV or Excel file, why not write a block in your macro script that opens the Jasper report, makes the pivot table then saves it again.
It's honestly been years since I've done VBA but this code was what I found online for opening workbooks (ref: http://p2p.wrox.com/excel-vba/10510-opening-excel-file-vba.html)
Dim oExcel as Excel.Application
Dim oWB as Workbook
Set oExcel = new Excel.Application
Set oWB = oExcel.Workbooks.Open(<pathToWorkbookHere>)
Forgive the syntax on this as it's from 10 year old memories, but from there, you could do things like
oWB.Sheets(1).Cells.Copy
ThisWorkBook.Sheets("PIVOTDATA").Cells.Paste()
ThisWorkBook.Sheets("PIVOTTABLE").Cells.Refresh
ThisWorkBook.Saveas("<path to new report>", xlExcel12)
If your reports are done by date, you could programatically select either the latest, load the folder and parse all of them, or whatever you'd like. Your template file is the one running the script, and saves copies of itself in a "does not contain a macro" state, so your users never get the security warning.
If you correctly determine the filename programatically, set the code to run "ON OPEN" in the template macro, and run a thisworkbook.close at the end of the script, all you've got to do is create a batch file that opens your workbook automatically on the command line
excel.exe <template_filename>
then set a windows cron-job (called a scheduled task) to run automatically every day, right after your jasper report runs.
Sorry if some of this is "hit and miss" in terms of syntax. I've not been elbows deep in Excel VBA for over 10 years, but I wrote a system like this at the time that was generating hundreds of beautifully formatted excel reports every day ... pivot tables and all.
It's totally achievable and you're on the right track.
By looking the answer on Jasper Tracker, seem that this feature is not supported by jasper report and will not be including in new feature
this (Adding VBA Script to Excel Generated Jasper Report) is such a specific Excel feature that I'm pretty sure we will
never implement. This is mostly because JasperReports is not an XLS
generating library, but rather a reporting tool with Excel output
capabilities
See this link for detail.