How do I Embed file in excel, use it and then embed new version again into excel workbook I'm creating a new Userform control for excel? - vba

I'm creating a custom Usercontrol (Userform) for excel, the name is Virtual forms.
The control is storing data in external file that is created in the same folder where the workbook is (example: VFFile.vf).
How to embed this file into excel (maybe OLEObject? or is there some other solution?)
More info:
I created a Usercotrol (ActiveX control) for excel, which uses an external file with definitions (VFFile.vf). And now to avoid that the developer always has to define the filename where this file on his computer is, I would like to somehow incorporate the file into Excel (when he drops this control onto excel worksheet the control will also put this file into excel workbook). Is there a way to do this?

I continue to use an external file because it gives me the possibilities to use this control in other environments, not only VBA with Excel.
For example, I can use it also in Python, or C# or VB.net.
Thank you guys for your tips and directions.
Davor

Related

Word formatting macro that calls another macro on a networked drive

I already have .docm files that have simple formatting macros embedded in them. The macros work. However I have 100+ different .docm files that use basically the same macro. Instead of changing the macros on all 100+ .docm files when I need to change a format, I would like to place the macro in a separate text file in a stable location on a network drive and have the macro code in each .docm file reference that text file.
I tried a Call Shell(AppName,1) statement where the AppName contains the path of the txt file, but the compiler won't work with a colon.
I researched creating a macro to change other macros embedded within each document, but was advised against it due to virus scanners.
It's not possible to run a macro from a text file, the way you imagine. (Cool idea, but a security risk, I think.)
Better would be to bring all the macros together in a single template (dotm), which you put in your STARTUP folder. When Word loads, it will load this template (with all its Ribbon customizations and macros) as an "add-in". (See also the Developer/Add-ins dialog box, which is where these can be managed.)
In this way, your code can be managed centrally - but you do have to explicitly open the template in order to make changes to the code. It can't be done just over the loaded add-in (that's only possible with Normal.dotm).
You can also have macros in this add-in template that you call from other macros. This can be done using the Applicaton.Run method.

A copy of Excel Addin is created in My Documents after saving

I have an application (running in IBM Notes, using Lotusscript etc.) that create a new Excel object via OLE automation. In my app I create a new Workbook and saving it to a temporary folder (I am saving it as Excel Worksheet w/o macros -> type 52) so that the resuting file is sth. like that:
tmp_abc1234.xlsx
Then I open the file in Excel programmatically. I have an Excel Addin (filename is "Teamoffice.xlam" loaded where some macros reside I will trigger in the custom save actionbar button. In this save method I also call the save function:
Call ActiveWorkbook.Save
Call ThisWorkbook.Save
For some reason Excel creates a file named "Teamoffice.xlsm" in the "My Documents" folder. The file itself cannot be opened in Excel ("wrong file format error") - of course, it's an Addin!
This works well if I have only one Excel document open from my application. If I open a second (or more) I run into trouble: everytime I save on of those secondary opened (or newly created) documents Excel asks me if I want to overwrite that "Teamoffice.xlsm" file.
I added VBA code to ma macro that detects if this file is there and tries to delete it. With no luck of course, as the first instance of Excel is locking that file already. Overwriting the file when aswering the Excel-question dialog works though, but I don't want that question to appear.
Excel doesn't behave like that when using it stand-alone w/o OLE.
Several questions resulting from this behavior:
Why does Excel create this file? Can I stop it from doing so?
How can I delete the file even if Excel has a handle on it or
Can I tell Excel not tohave a handle on this file (if it's there) and let me kill it?
Can I suppress the question dialog and always say "yes, overwrite it"?
Office version is 2010 - and it makes me going nuts... so thanks in advance!
p.s.: I am not that VBA pro, so please be as detailed as you can effort :-)
I noticed that
ThisWorkbook.Save
was the reason. If I omit it no file is created. Strange that this saved the Addin file as xlsm file though.

How to Make a VBA Excel Program Work on Other Excel Documents?

I'm very new with VBA Excel and i only know the things as far as i need for this report formatting task. My code is almost completed, but what i wonder is, how can i make my program work on several documents?
I mean, i want to choose an excel file via my program, then i want to start the process of report formatting. Then maybe user need to format another document, i want my program to be able to format that document too. how can i achieve that?
Thanks in Advance
Timur
The way I am currently doing this is by creating an Excel add-in. To do this, place your macros and forms into a new, empty Excel workbook and save as a .xlam document.
To use the macros, open the your Excel file and the add-in. To open the add-in automatically, save it to "C:\Program Files\Microsoft Office\Office12\XLSTART" (Vista).
You can even create a custom ribbon for your add-in using the Custom UI Editor for Microsoft Office http://msdn.microsoft.com/en-us/library/office/ee691832(v=office.14).aspx (The download link is at the end of the instructions)

How to Create VBA Add-In with Shared Codes for All Excels?

I'm writing VBA codes for multiple Excel spreadsheets, which will be shared with others from time to time. At some point I find there are lots of duplications in my works. So I want to find a way to share codes in a sort of Excel add-in, like the .xla file.
But when I tried to save the Excel file containing shared codes as .xla file, I got some problems:
The file cannot be edit anymore after I save it in the default add-in folder
If I move the .xls file to a folder other than the add-in folder, and open it directly - I cannot use its classes - which creates problems for sharing the codes
Any ideas to create add-ins in a flexible and powerful way please?
Thanks a lot for the help
Not completely sure this is what you're looking for, but ...
(1) save the .xla/.xlam code by clicking the save icon in the VBA editor. HOWEVER, the thing that saves is the thing currently selected in the Project Explorer pane, which lists all open VB Projects and which is usually on the left. Even if you are staring at your just-edited VBA code, clicking the save icon will not save your code unless it is also selected in the Project Explorer pane. You won't get feedback that anything was saved - but you can verify by checking the file timestamp in a separate window.
(2) if you have an *.xls file which (via the formula bar) refers to VBA functions from your *.xla / *.xlam file, then if you open the *.xls file without opening the .xla,.xlam file first, Excel may create external links to resolve the formulas (i.e. referring to a file which is not open). If you have moved or renamed the *.xla file you can get stuck with those "mangled formulas" and need to edit out the pathname links that Excel inserted using a global substitute. If you arrange to open the .xla,.xlam prior to any *.xls file that uses it, you shouldn't have a problem (e.g. by using the default folder).

Excel 2003 - How to build my own XLA?

How can you make the .xla file if you want to create your own xla? I have the code, classes, shapes, etc....what is the process to making an xla file to point to? I know that I have to put it in my program files folder, and then go through the steps to adding an "add-in" in xls...but i mean actually saving an xla file to point to....
can i simply write all this in xls and then save it as file type xla?? because i have tried to do that but I get an error that it is not a valid add in when I am in a spreadsheet trying to point to it?
thanks!
This should help:
Create an .XLA file
http://www.vbaexpress.com/forum/archive/index.php/t-496.html
http://www.xtremevbtalk.com/archive/index.php/t-62362.html
http://www.ehow.com/how_5066365_create-excel-xla-addin.html
Creating An XLA Add-In For Excel
http://www.cpearson.com/excel/CreateAddIn.aspx
Microsoft Excel VBA Macros. How to Create an Excel Add-in For Them
http://www.ozgrid.com/VBA/excel-add-in-create.htm
Excel VBA - install an Excel Add-in (XLA or XLL)
http://vbadud.blogspot.com/2007/06/excel-vba-install-excel-add-in-xla-or.html
If you are still having issues let me know...