Prevent Excel custom function running on file open - excel

I am building an Excel add-in with many custom functions. They work fine, however, when I close and reopen the file, all functions are recalculated. Since each custom function makes an API request to my website and the data does not change frequently, I am looking for a way to turn this feature off so that functions do no rerun on file open. I have looked through all the docs but could not find any answers. Really appreciate if someone could help me with this.
My add-in will be used by other users so I am looking for a solution that does not require any extra action from the (like setting the calculation mode of the spreadsheet to manual)

You can set up the manual calculation in the following way:
Application.Calculation = xlCalculationManual
Application.CalculateBeforeSave = False
The XlCalculation enumeration specifies the calculation mode.

Related

Add-ins not loading when opening excel file programmatically

I've seen some similar problems described by others before but no real solution. And I'm sure there is one.
I have a .XLA-add in configured to be loaded when I open up Excel. It works fine when I open documents or Excel it self. However, when my BI-system programmatically creates and opens an Excel-file the add-in does not get loaded. The BI-system opens Excel in a new instance so it does not help to have opened Excel on beforehand (and thereby the .XLA-add in)
If i Check Options-Add Ins it looks like the add-in is loaded but it is not!
What I've tried (and that does work) is to insert this function into the created excel-file and "reload" the add-ins, but I want to find an automated solution!
Function ReloadXLAddins(TheXLApp As Excel.Application) As Boolean
Dim CurrAddin As Excel.AddIn
For Each CurrAddin In TheXLApp.AddIns
If CurrAddin.Installed Then
CurrAddin.Installed = False
CurrAddin.Installed = True
End If
Next CurrAddin
End Function
Is there any way to load my Add ins automatically when instancing excel programmatically?
Any tips, solutions or workarounds are highly appreciated!
Best regards.
This may not be possible in VBA. I have come across this problem before, and used the implementation found here: Excel interop loading XLLs and DLLs
However, that solution is for C#. The steps required may not be possible when coming from inside of an Excel VBA script. Perhaps there are some VBA implementations you can look at, but wanted to give you some sort of starting place because I know that is a frustrating place to be.

Can I access and query web-based Crystal Report Viewer through Excel VBA?

I download reports through web-based access to a Crystal Report Viewer. (Admittedly, my first problem is that I am not at all proficient with Crystal.) I generally have success using Excel VBA in automating IE navigation and HTML form manipulation, but I've run into a wall with this Crystal Report Viewer.
As an example, I can download a report through the Crystal Report Viewer by specifying for which of the fifty states I want the report. I am trying to automate it so that it will export all fifty reports at once (or, rather, in succession while I, say, go to lunch).
I've pulled the outerHTML of the site in question. It includes an OBJECT tag at the beginning containing 23 PARAM NAME tags followed by the following VBScript:
Sub window_onLoad()
Page_Initialize()
End Sub
Sub Page_Initialize
On Error Resume Next
Dim webBroker
Set webBroker = CreateObject("WebReportBroker.WebReportBroker")
If err.number <> 0 then
window.alert "The Crystal ActiveX Viewer is unable to create resource objects."
CRViewer.ReportName = "[a URL...redacted]"
Else
Dim webSource0
Set webSource0 = CreateObject("WebReportSource.WebReportSource")
webSource0.ReportSource = webBroker
webSource0.URL = "[a URL...redacted]"
webSource0.PromptOnRefresh = True
webSource0.AddParameter "password", "[somepassword]"
webSource0.AddParameter "user", "[someuser]"
CRViewer.ReportSource = webSource0
End if
CRViewer.ViewReport
End Sub
This script was followed by three more OBJECT tags, each making reference to codebases. I navigated to these references to find DLLs, which I would assume indicate the references I need to invoke in my VBA. On a hunch, I moved the VBScript into Excel VBA (is this dumb?) and placed it after my usual login and navigating code. I get a "Compile Error: Variable not defined" on the lines
window.alert "The Crystal ActiveX Viewer..." 'highlighting the word "window"
CRViewer.ReportName = "[a URL...redacted]" 'highlighting "CRViewer"
CRViewer.ReportSource = webSource0 'highlighting "CRViewer"
CRViewer.ViewReport 'highlighting "CRViewer"
This is where I run into problems. First, I may be going about this the wrong way, or it may not even be possible; but I wouldn't know. Second, if I am on the right track, there are A LOT of Crystal references listed in Excel VBA's available references. I have no idea which ones to use. BTW: the codebases make reference to
crviewer.dll
sviewhlp.dll
swebrs.dll
xqviewer.dll
cselexpt.ocx
crviewer.dep
crviewer.oca and
reportparameterdialog.dll
Any help would be appreciated. I realize I may not have provided all the necessary information here. Please let me know if more is needed. Thanks for reading.
Is the Web viewer part of a wider Business Objects setup, or something more basic that simply launches a viewer with the report?
If it's the former, you already have easier options for automating distribution via the web-based CMC, wherein report refreshes can be scheduled with a variety of distribution options, including to UNC paths.
If its the later, or for some reason the standard CMC/BO options aren't suitable, you might consider using a code library made for this purpose. The splinter library for Python is one such, and my preferred package for web automation: http://splinter.cobrateam.info/
If VBA is your coding comfort zone, there are a few ways of integrating python into VBA, all merely a google away... I won't detail them here since that's a sideline to this, and my answer is more of an alternative than a direct answer.

Application.ScreenUpdating with calling functions from a plugin in Excel VBA

I am writing several big macros that reference a Salesforce.com Add-in called Sforce Connector. The functions in the plug-in don't seem to have Appication.ScreenUpdating set to False so the execution of the code is slowed down. I can't change the code of the Add-in, so I can't change the status of Application.ScreenUpdating. Is there a way to set it globally for a file or are there other ways of getting around this?

INsert value with Asp to excelsheet and call function?

I've got a real problem..
I got an webpage writen in traditionel Asp. What i need to do now is to insert a value to a field in a excelsheet. The thing is that the excelfile also contains som sub routines and i also what to call one of thoose routines after i inserted the value in the field.. Is this even posible?
Best regards
It's all possible (although you may have problems with security in automating Office from ASP, since the IUSR user generally does not have permission to do much), but it's not a great idea, since Office is not designed to be used in a multi-threaded / multi-user environment. If this is for an intranet, then it may be OK. If it's for a public website, I'd suggest finding some other route.
Those issues aside, driving Excel from ASP is no different from driving it from VBA, VBScript or VB. You can open workbooks, make changes, even call methods defined as VBA within the workbook. For the latter, use the Application.Run method.
EDIT: some sample code (from memory - may be full of syntax errors!)
Set oExcelApp = CreateObject("Excel.Application")
Set oWorkbook = oExcelApp.Open("file.xls")
Set oWorksheet = oWorkbook.Worksheets(1)
oWorksheet.Cells(1,1).Value = "foo"
oExcelApp.Run "'file.xls'!macroname"
oWorkbook.Save
oWorkbook.Close
oExcelApp.Quit

Excel Expert: need a good solution to fill some data into a complex excel sheet

I am stuck with a problem
The Requirement is that, there a complex Excel file(XLS) that is used as template; it has Macros and all the worksheets are either locked or hidden. When the user clicks to download it, the follows operation occurs
Unlock a particular worksheet, fill some data # certain cells and then lock it back.
Unhide a worksheet, fill some data # certain cells and then hide it back.
I think there are two options to resolve it (if there are more then please let me know)
Interop libraries / Excel Object Library
OLEDb Driver
I cannot got with the option 1 as excel is not installed on the webserver and I heard that it's not a good option to install MSOffice # webserver.
My question is that can we use OLDb to perform the operations mentioned above OR is there any other option ???
BTW Sharepoint service is also not available :(
Please help!!!!
You could maybe try ExcelPackge.
See this article:
Server-Side Creation of Excel 2007 Files Using .NET 3.0 and Office Open XML
see also:
Office Space - Building Office Open XML Files
Check out this question I asked some time ago for an overview of options. I ended up going with the Aspose library, which I link to in my original post. It's not cheap, but it does the job very simply and elegantly. It even has templating functionality built in (called SmartMarkers, IIRC).
SpreadsheetGear for .NET will handle this and has an API which is very similar to Excel. You can see what our customers say and download the free, fully functional evalution here.

Resources