I'm trying to hook a Window Form within Microsoft Excel itself like on the attached picture (This is an Addin called Kutools).
It is supposed to:
Fit on the right side of the Row number
Be Just below the name box
Be resizable and the window is resizable with it as well
Be collapsible or Expandable (like on the image)
I prefer to use the internal VBA of Excel to build and hook it as much as possible. But if I have to use an external Editor (Visual Studio C# or VB. Net ...) I'm willing to follow the instruction.
I searched all over the web but couldn't find a way to do this. I definitely appreciate your kind assistance on this.
Thanks for your help, I'm open to any suggestion!
If I am not mistaken, you are trying to create a custom task pane for Excel (add-in). If so, then this link might help you, but you need to build it with Visual studio using Office development tools:
https://learn.microsoft.com/en-us/visualstudio/vsto/custom-task-panes?view=vs-2019
Years ago I remember installing excel and office components onto the component palette in delphi 5. It was either through activeX or COM, or a typelib, there was some way to install the components. the components I think you could drag and drop onto the form and then a spreadsheet would be embedded into your app (or microsoft word, etc.).
The only information I can find on the internet is about using OLEcontainers... which is a component in the system tab of delphi 5. However I do not remember it being an OLEcontainer when I used components for embedding excel, I rather remember installing actual excel and office components onto the component palette somehow... the components may have been generated from an ocx file or a typelib, I do not remember. Where does one find or obtain the files to generate the excel and office components on the component palette? are they ocx and do they come with my copy of MS Office that I have on my computer?
Are there excel COM or activex components that one can install? Am I remembering correctly, or is the only way to use excel through OLEcontainer component?
Edit: it may have also been an automation server component for excel or office
You can do this:
In FormCreate (or OnActivate..)
OleContainer1.CreateLinkToFile( Edit1.Text, false );
This is the result:
Figured out how to at least import the excel components into delphi component palette (but these are not for embedding spreadsheet). Many people click "import activex control" but that will not import an excel spreadsheet component since the excel components are a type library import.
You cannot import the excel activex control the way you would think using "import activex control" menu item, rather you can import the type library instead.
Go to the main menu and click Project -- Import Type Library
Scroll down and find Microsoft Excel 14.0
(or whatever version of excel you have...)
then install.
The components appear on the component palette under activex tab.
Those are for automation. For OLE embedding, it seems that Ole container is the way to go.
I want to manipulate data in excel with some complex functions.
It seems that I have to use VBA.
However I don't want to learn it.
Is there any other way to do programming in the excel? Some language like C#?
I don't want to create a independent C# application using some interface provided by Excel. Only program in excel, like VBA, but a different language.
I don't want to create a independent C# application using some interface provided by Excel. Only program in excel, like VBA, but a different language.
You cannot unfortunately. To program in Excel from within Excel you will have to learn VBA.
To program for Excel, be it VBA, VSTO(C#, VB.Net) you need to understand the Excel Object Model (EOM) without which you cannot do programming for Excel.
You don't need to learn VBA per se if you want to develop Office solutions from C# but as you become familiar with the EOM, you will notice that you automatically develop an understanding for VBA.
EDIT
Excel Object Model from Excel's perspective
Excel Object Model Overview from VS's perspective
You can develop Excel "Add-Ins" in C# using VSTO - Visual Studio Tools for Office (MSDN link).
This is not truly "inside Excel," but once installed your add-in can run without having to start up any external application.
Excel has a VBA editor built in to use VBA only.
If you want to use another language it would need to be external.
While you could make a C# add in, this is not in the built in editor as you described.
To the best of my knowledge, you simply cannot do this right now. In Office 15 it looks as though you'll be able to use JS:
http://www.zdnet.com/blog/microsoft/microsoft-to-focus-on-html5-and-javascript-for-office-15-extensions/10266
Can a standalone .exe be created from an excel file which has a few forms and macros?
Standalone as in "the user doesn't have to have Excel installed"? No. It's still an Excel file; it needs Excel to be available to run it.
You may be able to get away with the Excel viewer though. Worth a try, if you're worried about licensing costs. It won't let you edit data though, which may well include forms... you'd have to try it to be sure.
Maybe an Excel viewer would be an option? I'm not sure how much support there would be for macros, etc.
SpreadsheetGear for .NET includes a Windows Forms control into which you can load an Excel workbook. The Excel workbook becomes part of the Windows Forms application (it is embedded in the .exe).
The bad news is that SpreadsheetGear will not execute your macros so you will have to rewrite them to the SpreadsheetGear API. The good news is that the SpreadsheetGear API is very similar to the Excel API.
Disclaimer: I own SpreadsheetGear LLC
So I'm having to run someone else's excel app on my PC, and I'm getting "Can't find Project or Library" on standard functions such as date, format, hex, mid, etc.
Some research indicates that if I prefix these functions with "VBA." as in "VBA.Date" then it'll work fine.
Webpages suggest it has to do with my project references on my system, whereas they must be ok on the developer's system. I'm going to be dealing with this for some time from others, and will be distributing these applications to many others, so I need to understand what's wrong with my excel setup that I need to fix, or what needs to be changed in the xls file so that it'll run on a variety of systems. I'd like to avoid making everyone use "VBA." as an explicit reference, but if there's no ideal solution I suppose that's what we'll have to do.
How do I make "VBA." implicit in my project properties/references/etc?
-Adam
I have seen errors on standard functions if there was a reference to a totally different library missing.
In the VBA editor launch the Compile command from the menu and then check the References dialog to see if there is anything missing and if so try to add these libraries.
In general it seems to be good practice to compile the complete VBA code and then saving the document before distribution.
I had the same problem. This worked for me:
In VB go to Tools ยป References
Uncheck the library "Crystal Analysis Common Controls 1.0". Or any library.
Just leave these 5 references:
Visual Basic For Applications (This is the library that defines the VBA language.)
Microsoft Excel Object Library (This defines all of the elements of Excel.)
OLE Automation (This specifies the types for linking and embedding documents and for automation of other applications and the "plumbing" of the COM system that Excel uses to communicate with the outside world.)
Microsoft Office (This defines things that are common to all Office programs such as Command Bars and Command Bar controls.)
Microsoft Forms 2.0 This is required if you are using a User Form. This library defines things like the user form and the controls that you can place on a form.
Then Save.
I have experienced this exact problem and found, on the users machine, one of the libraries I depended on was marked as "MISSING" in the references dialog. In that case it was some office font library that was available in my version of Office 2007, but not on the client desktop.
The error you get is a complete red herring (as pointed out by divo).
Fortunately I wasn't using anything from the library, so I was able to remove it from the XLA references entirely. I guess, an extension of divo' suggested best practice would be for testing to check the XLA on all the target Office versions (not a bad idea in any case).
In my case, it was that the function was AMBIGUOUS as it was defined in the VBA library (present in my references), and also in the Microsoft Office Object Library (also present). I removed the Microsoft Office Object Library, and voila! No need to use the VBA. prefix.
In my case, I could not even open "References" in the Visual Basic window. I even tried reinstalling Office 365 and that didn't work. Finally, I tried disabling macros in the "Trust Center" settings. When I restarted Excel, I got the warning message that macros were disabled, and when I clicked on "enable" I no longer got the error message.
Later I re-enabled all macros in the "Trust Center" settings, and the error message didn't show up!
Hey, if nothing else works for you, try the above; it worked for me! :)
Update:
The issue returned, and this is how I "fixed" it the second time:
I opened my workbook in Excel online (Office 365, in the browser, which doesn't support macros anyway), saved it with a new file name (still using .xlsm file extension), and reopened in the desktop software. It worked.
Even when all references are fine the prefix problem causes compile errors.
What about creating a find and replace sub for all 'built-in VBA functions' in all modules,
like this:
replace text in code module
e.g. "= Date" will be replaced with "= VBA.Date".
e.g. " Date(" will be replaced with " VBA.Date(" .
(excluding "dim t As Date" or "mydate")
All vba functions for find and replace are written here :
vba functions list
For those of you who haven't found any of the other answers work for you.
Try this:
Close out of the file, email it to yourself or if you're at work, paste it from the network drive to your desktop, anything to get it to open in "protected mode".
Now open the file
DON'T CLICK ANY ENABLE EDITING OR THE YELLOW RIBBON
Go to the VBA Editor
Go to Debug - - Compile VBA Project, if "Compile VBA Project" is greyed out, then you may need to click the yellow ribbon one time to enable the content, but DO NOT enable macros.
After you click Compile, save, close out of the file. Reopen it, enable everything and it should be OK. This has worked for me 100% of the time.
In my case I was checking work done on my office computer (with Visio installed) at home (no Visio). Even though VBA appeared to be getting hung up on simple default functions, the problem was that I had references to the Visio libraries still active.
I found references to an AVAYA/CMS programme file? Totally random, this was in MS Access, nothing to do with AVAYA. I do have AVAYA on my PC, and others don't, so this explains why it worked on my machine and not others - but not how Access got linked to AVAYA. Anyway - I just unchecked the reference and that seems to have fixed the problem
I've had this error on and off for around two years in a several XLSM files (which is most annoying as when it occurs there is nothing wrong with the file! - I suspect orphaned Excel processes are part of the problem)
The most efficient solution I had found has been to use Python with oletools
https://github.com/decalage2/oletools/wiki/Install and extract the VBA code all the modules and save in a text file.
Then I simply rename the file to zip file (backup just in case!), open up this zip file and delete the xl/vbaProject.bin file. Rename back to XLSX and should be good to go.
Copy in the saved VBA code (which will need cleaning of line breaks, comments and other stuff. Will also need to add in missing libraries.
This has saved me when other methods haven't.
YMMV.