In the IDE: Run a function on a selection

Guus2005

AWF VIP
Local time
Today, 11:43
Joined
Jun 26, 2007
Messages
2,642
This is probably asking to much but here goes nothing:

I am looking for a way to select a piece of code in the IDE (VBA window) and then run my own function on it to modify the code in the selection.

example:
Code:
'From:
    Dim intLongest As Integer
    Dim vItem As Variant
    Dim intItem As Integer
    Dim strRetVal As String
Run some function which results in:
Code:
' To:
    Dim vItem      As Variant
    Dim intItem    As Integer
    Dim strRetVal  As String
    Dim intLongest As Integer

Can you think of a way without writing an add-in?

Thx!

a link to the basX module containing the sort function i wrote earlier
 
Well yes, it is possible, I think! But from my very limited experience with it; it's a pain. I may be wrong in this but my recollection is you have to extract each line, work on it and put it back.... and still, it's not quite as simple as that... The reason I'm woolly about it is I had a go and it was just,- well not the way to go, for me anyway...
 
Hi Guus, by the way are you anywhere near amersfoort?
 
Yes it is possible but as Tony says you would normally do it line by line.
You need the VBE extensibility library to do so.
Chip Pearson's site explains the idea very thoroughly.
http://www.cpearson.com/Excel/vbe.aspx

Another way is to use a template text file and code to write procedures.
I'm using that approach with my JSON parser to write transform functions for individual files.
You can see an early version of that here
https://www.access-programmers.co.uk/forums/showthread.php?t=295789

It takes a while to master but is a very powerful and flexible method.

Having said all that I've looked at the From and To lists.
The only difference is the order.
Why does that matter?
 
Having said all that I've looked at the From and To lists.
The only difference is the order.
Why does that matter?
Difference is that the "as" keyword is lined up and the variable names are sorted to their length.

I believe it looks nice. But that's personal. It has no functional value.

Thanks for your input!
 
Difference is that the "as" keyword is lined up and the variable names are sorted to their length.

I believe it looks nice. But that's personal. It has no functional value.

Thanks for your input!

Ah I see. I didn't even notice that! :)
In that case most of what I wrote was completely irrelevant....
 
Last edited:

Users who are viewing this thread

Back
Top Bottom