I have an add-in that helps fill Excel tables with data from Atlassian Jira, used by several kinds of Excel files. The add-in has been created with the Excel VBA editor, not VSTO.
Now I need to use the functions of this add-in from macros in a Word template.
To avoid duplicating the code base, I would like to use this add-in in Word.
Trying to add a reference to the Excel add-in in Word triggers the error "Can't add a reference to the specified file".
Is there a reasonably simple way to achieve this?
If you want the best next thing you can do is inserting Excel table into Word document and then adding to that document your VBA code.
To add the Excel tabel just use Insert -> Table -> Excel Spreadsheet -> your toolbar will change to excel toolbar with the option for adding your VBA code like in Excel.
When using Excel, pressing CTRL+* (asterisk) when the cursor is inside a table, automatically identifies the table and selects it.
Is there a way to do exactly that when writing an Excel add-in in Visual Basic using Visual Studio 2013?
Use the Macro Recorder to generate the equivalent VBA object model calls: that should give you enough information to identify the VB.NET Interop calls.
(Using the Macro recorder in this way saves hours of trying to work things out from the documentation)
In this case you get
Selection.CurrentRegion.Select
I have a report that I run from a system once a week, and the data is exported into an excel document. I have set up the tool that exports the data to excel to do a decent job on formatting, but there is still more that I need to do once the data is in excel.
Is it possible to create a stand alone macro, save it in a Microsoft office folder and be able to call it after I open this file? I have written plenty of macros that are part of ONE given spreadsheet, but never tried one that was open to many spreadsheets.
IS it possible, and a starting direction of good resources of where I can learn how to achieve this goal? Thank you.
...and be able to call it after I open this file?...
You have 2 very good options
1) Write and save your macro to Personal file. See this link for more information
Topic: Deploy your Excel macros from a central file
Link: http://office.microsoft.com/en-us/excel-help/deploy-your-excel-macros-from-a-central-file-HA001087296.aspx
Quote from the above link:
Have you ever wanted to use that really handy macro in all of your Excel worksheets? You can. This column explains how to place your macros in a file called personal.xls and make them available each time you start Excel.
2) Create an Add-In
Topic: Creating an Excel Add-in
Link: http://msdn.microsoft.com/en-us/library/aa140936%28v=office.10%29.aspx
Quote from the above link:
You create a Microsoft® Excel add-in by creating a workbook, adding code and custom toolbars and menu items to it, and saving it as an Excel add-in file.
I have some pivot tables in powerpoint that I embedded. I chose to embed rather than just regular linking as I need to update the pivot tables daily and need to shape them to give only the relevant information.(Sometimes there is more data than the day before which cannot be seen when linking normally as the"window" is fixed.)
I am still very new to the VBA coding field and require a code that will open my Microsoft excel worksheet opject then refresh the pivot inside the object and close it again. I have written code to open the document, save and close the document which is working correctly. I only require that little refresh bit.
Many thanks in advance
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.