Objects - How do they work

Stildawn

Board Regular
Joined
Aug 26, 2012
Messages
201
Hi All

I am working on a few VBA codes, and I am looking into using Objects to hopefully get over one of the hurdles I'm facing.

I have not used Objects myself personally before and after googling around what I have read about Objects is confusing as hell haha.

Just wondering if someone can walk be through in real simple terms how to create an object...

Basically what I want to do is create an object with the this code in it:

Code:
.GetText(CursorRow, CursorColumn, CursorRow, CursorColumn + 1)

This code simply generates a string based on the co-ordinates the cursor is at.

I want to put this into an object because I'm hoping this will make my other code (which needs to call the string from the cursor co-ordinates) able to work and making the Cursor co-ordinates update each time the object is called.

I have tried a simple Dim statement with the .GetText command, but it never updates the cursor position, its sets the cursor position from the moment you run the macro, where as it needs to update based on a new cursor position each time I need to use that string.


Anyway after reading around and a few trials and errors I just don't understand how to do this, I have created a Class (called Class1) and put the above .GetText code in it.

Then in my normal Sub, I have used the following:

Code:
Dim xyz As Class1
Set xyz = New Class1

I'm hoping to run

Code:
Set xyz = Nothing

Command after each time I need the string, so that hopefully it refreshes the cursor position since I clear the data for the object?

This is what I got from reading around, but its obviously wrong and I'm missing something important, however all the examples I can find are trying to make complicated objects, where as mine is really simple...

Any help would be greatly appreciated.

Thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,225,637
Messages
6,186,137
Members
453,339
Latest member
Stu61

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top