PDA

View Full Version : How to Declare Object Variable with Direct Memory Access?



johnywhy
07-22-2021, 02:26 PM
I want to declare a variable by directly writing the declaration directly to memory. i assume we need to create in memory:


Variable name and type info. Eg, "MyWorkbook"

I assume the variable can be created using commonly available methods such as StrPtr, VarPtr, ObjPtr, CopyMemory, etc.

Once created, then the variable could be instantiated with normal VBA (not direct memory access), using the variable-name as normal. Eg:

Set MyWorkbook = Workbooks(2)


Assume 64-bit (PtrSafe declarations etc)
Office 2016

Paul_Hossler
07-22-2021, 05:56 PM
Might be impossible, but Why?

johnywhy
07-23-2021, 12:03 AM
Might be impossible, but Why?
Power, speed, flexibility, ability to declare variables with strings, ability to declare variables in immediate pane, unknown future applications. To expand my skillset.

Also asked at
https://stackoverflow.com/questions/68495231/how-to-declare-vba-object-variable-with-direct-memory-access

snb
07-23-2021, 02:40 AM
Use With ... End With instead of Set.

johnywhy
07-23-2021, 02:53 AM
Use With ... End With instead of Set.
wrong thread?

snb
07-23-2021, 04:02 AM
Please read again and try to understand.

johnywhy
07-24-2021, 11:02 PM
Please read again and try to understand.
no idea