Create copy/paste button - ms-access-2007

Is it possible to create a 'COPY' and a 'PASTE' button in MS Access 2007 on a form.
Is there a code sample I could use, or a macro to copy a field and paste a field.

For API code to copy text to the clipboard:
http://www.mvps.org/access/api/api0049.htm
For getting data out of the currently active control, use:
Screen.ActiveControl.Value
Put these two together and you should be able to figure it out.
If you can't, just post back and I'll provide more detailed instructions.
(there's also DoCmd.RunCommand acCmdCopy, but the data you're copying has to be selected for that to work, so it's actually harder to code that than it is to use the API for the clipboard)

Related

How to add vba code in ms access

I am using web app, and I want to add the vba code after I update the Open date.
but when I click after update, I can just add macro, there is no vba code options.
I google it but I can't find any property sheet even I click right. How can I add the vba code there?
You can't. Access web apps don't support VBA code. There is no way to work around that, to my knowledge.
You can always migrate to a normal database.

Control Button to initiate the writing of a new VBA macro

Would it be possible to have a control button (or any mechanism) that once clicked on, a textbox would appear with fields like macro name Sub "NewMacroTitle"(), a field for the date, a field for reference sources ("Getting Links/URL from a webpage-Excel VBA"found this here"), a brief description of what the macro is to do. All of these fields, except Sub "NewMacroTitle"(), would start with a ' to show a comment and all of this would be inserted into the VBA editor, or enter it into cells on a spreadsheet that could then be copied and pasted into the VBA editor.
My problem is this. I'm new to VBA. I'm also the world's worst at documenting macros. I get an idea for a macro, I'm off into the VBA editor writing away, maybe even get the macro complete. A week later I'm reviewing the macro and the first thing is "what the heck does this thing do?"
I hope you see what I'm trying to do, essentially some way to force me to document the macro before even starting the actual code.
There are tools that will add pre-defined text to the header and/or footer of a sub. I use the one from MZ Tools for error handling code and adding my name and date to the header of each proc. It is worth a look.

Centralized VBA code for multiple Word files

I have multiple files with the same VBA code in them, which will most likely have to be changed over time. I don't want to go one by one and c/p the code, so one obvious idea that came to mind is to have one centralized document with the code (template?) that all files refer to.
I found a few topics here at stackoverflow, but none of them work for me or are inconclusive:
Run external vba-code in MS Word
Centralized VBA code (one file) for multiple workbooks
Calling an External VBA from VBScript
Any ideas?
Yes, your idea of centralizing the code in a template and attaching that template to the various Word docs will work. These pics are using Word 2007 but I think it's pretty similar for newer versions. First create a new document and put the code in a Module (named "CommonFunctions" in the picture):
Save the doc as a macro-enabled template:
Now make a new document, save it as a *.docm (necessary for it to run code because a *.docx is macro-free), and attach the document template as shown below. (An alternative is to put the *.dotm file in the startup directory C:\Users\<username>\AppData\Roaming\Microsoft\Word\STARTUP, which loads it automatically.) If you don't put it in the Startup, you'll see the name but it won't be loaded (ie, checked), but you can load it in code, as I'll show.
Make a user form in this document:
Put this code for the button's click event:
If AddIns("c:\_b\MasterDocWithFunctions.dotm").Installed = False Then
AddIns("c:\_b\MasterDocWithFunctions.dotm").Installed = True
End If
Application.Run "CommonFunctions.Test1"
Application.Run "CommonFunctions.Test2"
Notice how the code can load the AddIn for you, because it won't be automatically loaded unless you put it in the Startup directory. This pic shows how the AddIn is referenced but not loaded. You need the checkbox to be able to call code in it. If you don't load it using code and don't put it in the Startup, then the user will have to manually put a checkmark everytime the document opens.
Now the form should work when you click the button. Notice how it can call both public and private functions. The Private keyword definitely shields one module from another, but it seems like modules that are called from an AddIn are considered to be part of the same module, not sure why? Also if you don't put Public or Private at all then VBA considers it Public, I'm pretty sure.

Display Excel inside VB6 / VB.NET Form & work with Excel without excel menu

I have an Excel sheet with Macros enabled. I want to display the Excel sheet inside a VB6/VB.NET form without excel menu header and perform excel activities inside the form.
Please note that I need to perform some macros actions when some cell is entered...
My Objective is to create a standalone VB6/VB.Net Form in which excel cells should be displayed for performing marco actions.
I have tried searching for any sample but no luck. It should be something like this...
Can any one hint me to achieve this ?
As far as I can tell - this is not possible. The reason being that you cannot subclass the excel window in VBA.
If you program outside of excel with VB.NET or VB6 it would be sort of possible, but would probably not work really good.
If you only want to display some data from a sheet and perform some small actions on them, you could probably read the Data via the EPPLUS Library, display them as a datatable (EPPLUS can convert between datatable and excel files), perform your actions and save them to the file afterwards. But this would only work in VB.net
I did a lot of research into this last year. There is no available package to do what you are asking that is provided by MS or for free, however, you could create a datagridview (DGV) in vb.net and load the data into the DGV via ADO.NET. The data loaded into the cells will mirror your spreadsheet. Then when you modify the cells in the DGV, have a label as you have shown to update the data changes back to the excel sheet.
http://social.msdn.microsoft.com/Forums/en-US/7a1c828d-04ed-4a8d-927d-3649f29d2060/import-data-from-excel-sheet-into-datagridview
As far as calling the macro, use the excel interop feature to call a macro:
http://social.msdn.microsoft.com/Forums/office/en-US/2e33b8e5-c9fd-42a1-8d67-3d61d2cedc1c/how-to-call-excel-macros-programmatically-in-c
There may be some third party support for what you are doing, but of course it costs money:
http://www.componentone.com/SuperProducts/SpreadStudio/?gclid=CLKIy6TqwLkCFYZlOgodhToAZg

Please let me know feasibility using Excel and VBA programming and suggest solution approach

We have following requirement to be done via excel and VBA programming. Please check and let me know if it feasible to do so and if not what way would be best to do it.
There would be excel spreadsheet say excel 2007/2010 with 2 tabs.
1st tab contains normal excel data
In 2nd tab user can enter a particular value and then click on a button in same tab. Is it possibly to have a button in excel tab and can it raise events like windows/web applications?
Now if button can be kept in excel and it can raise button click event then on such an event we need to create xml files. Is it possible to create xml files adhering to schema using excel &/or VBA programming
You need to activate the developer tab (from backstage go to Options and check the visibility of this tab) to get access to normal windows controls, like buttons and drop-down lists etc. You can easily place those in Excel sheets and write event handlers: the controls support the full range of events, including OnClick, OnMouseEnter etc...
You can write custom text files directly from VBA, but you can't validate those. The usual way to do so is just to concatenate small XML blocks into a bigger file, so XML output is more like a normal text output. But it works fine and as long as you do not need to perform something really complicated it is also ok.
EDIT: You can easily add references to custom COM objects (.dll or .ocx) and use them directly in your VBA code. One very helpful suggestion (see the comment below) is to use the MS XML library.
To add a reference just open the code editor (Alt + F11) and then go to Options -> References. Most of the references you need will be already in the list and you just have to check them, but you can also add your own custom libraries by clicking on Browse.