Is it possible to create an 'access' macro through automation? - vba

I have been searching this for a while without any positives . We can create new modules, form ,report, but macros .Can we at all do this? This post asks the same question but answers another one.
"Create a macro for Microsoft Access via Interop "
here VBA module is being added not macro.
Theoretically it seems feasible as macro is an access object so why we cant do it ?

I dont think you can create macros via vba.
There is an object AllMacros (Application.currentproject.allmacros) and its members are representations of the individual macros in your project - but they are of the type Object, thus there doesn't seem to be any vba representation of the macro object.
You also can't import macros, autogenerate them or convert from vba to macros... So it seems pretty obvious ms isnt encouraging using them and hasn't done anything for us to create them

Related

unlocking a vba project with vba, knowing the password?

I think that question has been asked in different ways. But I didn't found a satisfying solution. I want to unlock a VBA-project using vba code. Possibly something like the .unprotect method for workbooks or -sheets. I know the password, I do not need to crack open the project.
Is there a simple way to realise this?
Thats not possible. The Password is not exposed in the VBA Object, so you cant directly access it trough VBA Code. There is only a method to send the keys for the password, but i wouldnt recommend it.

Process id / Window handle late binding in Excel VBA

I got a problem regarding late binding, and hope there is someone who can help me.
I have searched Google dry regarding my issue, and most solution do not fit at all.
I am binding a Excel macro written in VBA to my own program to communicate, it works fine with GetObject(). However GetObject() gets a random instance, and I don't want that since there can be multiple instances open at the same time.
When I open the Excel through a C# program, I pass the window handle and process ID of the newly opened instance as arguments to the excel.
How can I do a late binding in Excel VBA by only using either process ID and / or window handle?
Thanks in advance.

Excel VBA not auto-assigning variables

I've written a macro in Excel VBA, which I have used many times before. Today I loaded it up and it wants me to define all the variables (before I let Excel auto-assign everything). When I assigned all the variables, it then didn't recognize simple VBA functions like trim, split, again which it always has before.
I'm not using option explicit. Any idea what my problem could be?
It might have something to do with a recently installed a trial Excel addin (from a respectable company), the trial ran out and I uninstalled the addin, now none of my macros work.
did you try turning off the OPTION Explicit requirement in the VBA Options:
To do this go into the VBA editor ─► Tools ─► Options ─► Editor ─► uncheck Require Variable Declaration.

Loading (and executing) a lisp-file in autocad using .NET

I'm currently in the process of rewriting some old AutoCAD plugins from VBA to VB.NET. As it turns out, a (rather large) part of said plugin is implemented in LISP, and I've been told to leave that be. So the problem became running LISP-code in AutoCAD from .NET. Now, there are a few resources online who explain the process necessary to do so (like this one), but all of them takes for granted that the lisp-files/functions are already loaded. The VBA-function I'm currently scratching my head trying to figure out how to convert does a "(LOAD ""<file>"")", and the script is built in such a way that it auto-executes on load (it's a simple script, doesn't register functions, just runs from start to end and does it's thing).
So my question is. How can I load (and thus execute) a lisp-file in autocad from a .NET plugin?
Ok, there are two ways to sendcommand via .NET.
The first thing you need to understand is that ThisDocument doesn't exist in .NET.
ThisDocument is the document where the VBA code is written, but since your addin is document undependant, it stands alone and you must take the documents from the Application object.
You access the application with:
Autodesk.AutoCAD.ApplicationServices.Application
If you want to transform it to the same Application object as in VBA, with same methods and functions
using Autodesk.Autocad.Interop;
using Autodesk.Autocad.Interop.Common;
AcadApplication App = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
The first application has MdiActiveDocument, from where you can call the Editor and send written commands, or call the SendStringToExecute as said in other answer.
The AcadApplication has ActiveDocument (an AcadDocument object that behaves exactly as in VBA).
This document will have the same SendCommand your VBA has, use it the same way it's done in VBA.
If you can explain better the autoexecute part, I can help with that too.

VBA: Dim Control Object Failed

Just have no clue why the code below kept complaining about "user defined type not defined":
Dim ownControl As Control
I saw all other resources online used this code without any problem. Really confuse on it, hope someone can explain to me.
By the way, I'm using MS Excel 2007. Thanks a lot
Most likely you will need to first add a UserForm to your workbook (assuming you're going to be using one) or instead add a reference to "Microsoft Forms 2.0 Object Library".
The Control type is defined in that library.