My problem seems very basic and I was surprised to not find an answer after searching. So I would like to keep my library references between startups of Excel but they seem to reset every time.
I am using dictionaries in my VBA code so I need Microsoft Scripting Runtime enabled. How do I keep this reference up? Or is there a way to force it through my VBA code? This would actually be the best solution as this tool is going to be used by a few other people in my organization.
Someone has a solution to this? Any help is greatly appreciated.
With this question you're essentially getting into the topic of early binding vs. late binding.
I'm assuming what you're doing now is early binding, which means you are adding the reference manually from the tool bar.
To persist the reference I'd suggest going with the late binding route.
Add the following lines to your code:
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
From there you can access the dict object by doing dict.method/function.
I'm providing you a few examples below that should help you get the idea of how to utilize this:
dict.add key, value
dict.remove key
dict.count
Given you're already working with the dictionary you probablly have a general understanding. If you need to understand more of the built in methods/functions refer to the following documentation:
https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/x4k5wbx4(v%3dvs.84)
Related
I'm trying to run an Excel macro with late binding code that looks like this:
Dim oThisObject As Object
Set oThisObject = CreateObject("ClassNameString")
It works fine on my machine but on my coworker's machine it's failing. I checked the references and he has the necessary reference checked (included). If I do early binding it works fine on both our machines. That would look like this:
Dim oThisType As ThisType
Set oThisType = New ThisType
How can I determine what to put as the "ClassNameString" on his computer to make late binding work.
I was googling around and found some example code that shows that exact class as something like this: "ClassNameString.1" but that didn't work on either of our computers.
My guess was that these names were in the registry somewhere and might possibly be different to avoid conflicts or something but I couldn't find anything to support that theory and when I searched my registry for the exact string I use I didn't find anything.
I also found this question which is similar from a few year ago but has no answers:
Late binding creating object VBA
So I'm currently working with VB.net and winforms and I need the have objects created from my classes saved so they are still there if I exit the program and open it again.
I also needed to make them dynamically so I was going to add them to a dictionary on creation and save that dictionary in the settings, but it seems that you can't save a dictionary in settings.
So how can I do this? Maybe something like save the creations in an excel sheet and recreate them on load each time, that might work but seems a tad inefficient, Thanks in advance, Ed.
(p.s. sorry if this makes no sense it's 1:30am in the morning here and I'm not really with it.)
So just putting this here in case anybody else has this problem, I took Plutonix's advice and looked into serialization and it sorted my problem, used this video: https://www.youtube.com/watch?v=oN_YHn3EVOs
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.
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.
Im trying to build an error-logger that loggs running values that is active in the function that caused the error. (just for fun so its not a critical problem)
When going in break-mode and looking at the locals-tab and autos-tab you can see all active variables (name, type and value), it would be useful to get hold of that for logging purposes when an error occur and on some other occasions.
For my example, I just want to find all local variables that are of type string and integer and store the name and value of them.
Is this possible with reflection? Any tips or pointers that get me closer to my goal would be very appreciated.
I have toyed with using expression on a specifik object (a structure) to create an automapper against a dataset, but I have not done anything like what I ask for above, so please make me happy and say its possible.
Thanks.
If you're looking to reproduce the behavior of the debugger, then you may want to be a debugger. See the Visual Studio Extensibility Learning Center. In particular, see the links under "Debuggers".