How to call a MS Access database macro from C# - c#

I just wanted to know whether it's possible to invoke a module function or a macro in MS Access database from outside. Using C#
Thanks

Yes. You can run macros.
This Article (only available via archive.org) shows everything you need.

Related

Share code between office applications

I have written two addins , 1 for excel and 1 for word. However these addins have a lot of duplicates: Database handling, file handling,array handling which I would like to update 1 place instead of two.
We do have access to sharepoint, and could get access to visual studio. The thing is that people like to use file explorer and find the correct word or excel file, then open it then press a button inside the application which then should do things with the active document.
This is why we haven't written it as a .Net application yet, because that requires that people browse for the file inside the .NET application uless I am mistaken.
Is it possible to make an Addin which works both excel and word, or a dll? AnAnother important thing is that it should be easy to roll out a new version to the user, like stored on a network drive or similar.
Yes it is possible
The Hard Way
You can create a .Net DLL and call it from VBA. In visual studio a lot of people use Unmannaged Exports by Robert Giesecke to create DLLs that don't need to be registered (that way the DLL can be shipped with your document, and as long as it can be found you can use it).
Alternatively you might be able to do it manually as shown here by Hans Passant.
The Easy Way
Once the DLL is created you can declare it in a VBA module the same way you declare any other DLL for Late Binding and then call it from your code.
OR if you're happy to create the DLL and add it as a reference (possibly less portable) you can make it COM visible and register it for COM Interop in Visual Studio; this is probably the easiest way to go because you can then use Early Binding.
This is a walk through that might help: http://www.geeksengine.com/article/create-dll.html
But if you want to store the DLL on a network drive, well it might be that you really want to look at doing it the 'hard way', in which case look here: https://stackoverflow.com/a/5934745/3451115 and here: https://msdn.microsoft.com/en-us/library/bb687915.aspx

How do I get my dynamo code into visual studio?

I currently have a dynamo project with a useful macro that I use in Revit, however, I can only run this if I have dynamo and Revit open at the same time.
I would like to add this macro onto my ribbon tab within Revit but cannot do this while the macro is built in dynamo.
Is there a way I can either:
Export the macro I have made inside dynamo into a .dll?
Open it up in visual studio and build the code in there?
View the code in dynamo?
Many thanks,
Dan
There are a number of ways to achieve this.
Most of them involve several different translation steps.
All of them would require you to access, extract and save the Python source code in an external text file to begin with.
Not being very familiar with the Dynamo and Python side of things, coming from the C# .NET add-in side, I would suggest trying to integrate your code into the pyRevit IronPython script library once you have it in hand:
http://thebuildingcoder.typepad.com/blog/2016/04/the-pyrevit-ironpython-script-library.html
Afaik, that is easy and provides exactly what you are asking for.

Call VB method in C# using Interop

Okey here's the situation: I've got a microsoft excel macro in vb that I want to call using C#. I've already tried creating a workbook using Microsoft.Office.Interop.Excel, however I don't want to have to run an excel process to run the macro.
So then I thought why not make a vb class library with my code in it so i can still run it and have a clean dll file. It's not needed to keep any sheet related functions since the macro reads a .lua(UTF-8)text file with some advanced regex functions that I just can't get recreated in C#.
Is it possible for me to make the library use interop as well so i can just call the function in my C#? Any examples would be greatly appreciated.
First I assume you are working with VB6 and not VB Script?
I have never worked with VB 6 or earlier, but I think your best be will be to create a COM object and then you can call the COM object from .NET using C#. Here is a quick link I found through BING that I believe will help you get started if this in an option for you.
Walkthrough: Implementing Inheritance with COM Objects (Visual Basic)
I noticed these two statements:
I don't want to have to run an excel process to run the macro
and
the macro reads a .lua(UTF-8)text file with some advanced regex functions that I just can't get recreated in C#
Those two goals are incompatible. The macro relies on excel functions to run. The only way provided by Microsoft to accomplish this is to completely load the Excel app. There is no way to only run the macro.

Accessing C# user settings from a C++ Application

I am writing a C# program in Microsoft Visual Studio 2010 that stores some information inside of the local user settings like so:
Properties.Settings.Default.userActive.Add(connection.Active);
Properties.Settings.Default.Save();
I also have a Visual C++ application that would like to read these stored user settings. Is it possible for my Visual C++ application to read the C# application's user settings?
Similarly, how would I go about accessing the local user settings directory in C++?
It seems like there is no Microsoft sanctioned way to do what I am attempting to do. In case anyone else comes across this I will briefly explain what I've decided to do. Here was a helpful guide. I am ultimately just populating an xml file from the C# and placing it within the users AppData folder located at:
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
I am then using my C++ to locate it using:
TCHAR myCharArray[MAX_PATH];
SHGetFolderPath(NULL,CSIDL_LOCAL_APPDATA,(HANDLE)-1,SHGFP_TYPE_DEFAULT, myCharArray);
I then parse the XML file using C++ and read in the settings. This was a much more manual process than I would have liked, and leaves room for a lot of error unfortunately. Anyways, thanks everyone and good luck!
You can make the c# class COM callable through .NET COM Interoperability and COM callable wrappers.
Check out
http://blogs.msdn.com/b/deeptanshuv/archive/2005/06/26/432870.aspx

Compact Access 2007 DataBase File In C#

I want Compact a Access DataBase File in C# by Code.
please Help me
Edited: I USe Microsoft Access 2007 DataBase File
The easiest way is going to be by using the standalone program “JetComp.exe” and just calling that from your c# code
http://download.microsoft.com/download/access2000/utility/1.0/win98me/en-us/jetcu40.exe
Another option would be to open a DAO connection to the database and use the .CompactDatabase method. Not being a c# bod I cant really offer a code sample but it is quite easy to do in VBA, for that reason I would just use the first option
I would use Jet Replication Objects (JRO). For example code, see here.
Not a C# programmer...but could you Shell to something like:
c:\myFolder\myAccessDatabase.mdb /compact
This as you can see uses the command line switch /compact.

Categories

Resources