i have an excel file template and i want save the written value in textboxes to the cells of excel using vb6 language.
can anyone help me?
You can do this using Excel's automation features from any language that supports COM (directly or indirectly); here's an example using VB.Net. There are also examples using VB6 out there still, but see my comment on your question, creating new applications with VB6 is a potential problem as the dev environment (compiler, for instance) is no longer supported (the runtime still is, for a little while yet, to support apps that already exist). The dev environment still works (under XP, at least) to my (sad) knowledge, but expect it to start having trouble as OS's move on...
Related
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
I just started to learn VBA. As far as I understood, one uses VBA to write macros in MS-Excel. But I wonder if it the only area of application for VBA. Can it be also used like many other standard languages - like Python, for example.
If it is the case, how can I compile a VBA program? Should it be compiled? How can I run such a VBA program?
VBA is compiled to p-code. P-code is an intermediate language that requires an additional runtime in order to execute. This runtime is hosted by most Microsoft Office applications (including various non-Microsoft applications).
In short, you cannot write a VBA only app that is compiled to an .EXE.
To create a stand-alone VBA-like program, you would need to use Visual Basic 6 or earlier. The successor of Visual Basic 6, of course, is VB.NET, which is a very different animal.
VBA can be licensed, and there are quite a few pproducts outside office that use VBA. MS no longer issues new licenses. There are non-MS VBA implementations, like from Summit software. In any case you need to have your own product that would host VBA.
A notable application supporting VBA is AutoDesk AutoCAD. It licenses the VBA runtime and has its own object model.
If you don't compile the program ahead of time (in the Visual Basic Editor click Debug -> Compile), then Microsoft Office compiles it at run time. You really should compile frequently though because that is how you find compile errors.
How you run a VBA application depends entirely on how you have set it up to run. In Excel for example you can have the Workbook_Open event start your code when the workbook is opened or create custom menus that users click on to run the code. In Access, you can set a form to display when the database opens or create an autoexec macro that will run when the database opens. etc. etc.
Like someone else said above, you can't create .exe files of VBA. The code has to run in a Microsoft Office Application.
I have a COM dll that works fine in a excel 2007. I'm trying to get it work with excel 2010, and it seems to work fine at first, and then the excel suddenly cruses, and produce a .dmp file.
Does excel.interop version 12 can be used on excel 2010?
Is it possible to examin the dmp file that produced after the crush, and if so how? (tried windbg, i have no idea how to use it)
Thanks
Excel.Interop version 12 should work with Excel 2010 because COM components must be backward compatible (the interfaces found in Office 2010 must be compatible with the ones that exist in Office 2007)
The first step to carry out with your dump file is to load it in the debugger, setup the symbols correctly ('.symfix') and then launch the '!analyze -v' command. If the produced analysis and the callstack doesn't help you to pinpoint the problem, then you'll need advanced skills to debug the problem (memory corruption, debugging, ...).
I have been working on an excel file which will combine each of the excel files
sent by the users. So I will have a user entry row per file.
I started by using VBA. I thought that it would be the best, natural choice, though
I did not know how to use it previously. At the moment I have come across problems that I have no idea how to solve in VBA - I want to open each of the excel files that contains a user form seamlessly even if it contains VBA code, but what happens is that each opening user gets a dialog that requires them to accept or reject VBA.
I really like to learn new things but it is starting to annoy me. I do hope there some other solution to do that, but not in VBA. Is it possible to do that in some other language, and fire it from VBA?
I would love to have all bounded in that master excel file, or at most just to provide some library. The excel version is 2003.
how are you opening the file? Workbooks.Open will open an excel file which has vba without asking the user to accept or reject code.
Perhaps its an issue with the security settings you have. You can check these out from the menu - Tools, Macro and then security
your question is not well defined.
if you need to manipulate Excel files without opening Excel program, you can use other programming languages. Either interface with the COM / ActiveX objects that excel provides to the operating system, or use independent libraries (e.g. for PHP, Java, Python and more).
Another solution (to whatever problem you may have) is to use OpenOffice for working with excel files. It has its own macro language, as well as built-in bridges and interfaces to java & python.
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.