February 2006

Go Sub, to go?

I was flicking through John’s recently opened Hard Core XL VBA site (well forum), theres a lot of content there, it’s a nice way to store a lot of code. One thing that i had never seen before was the go sub method

Basically you goto a Lable, excute whatever code follows and finish with a return line, viz

[vba]
Sub Test()
x = Array(1, 10, 100)
For i = 0 To UBound(x)
If x(i) > 10 Then
GoSub ValueError
End If
Next
Exit Sub
ValueError:
MsgBox “the ” & i & “th vlaue in the set X is more than 10.”
Return
End Sub
[/vba]

Now i didn’t know you could do that!!!. I think i’d still be inclined to farm it out into another sub or function, but it could be useful all the same.

Moving a captionless userform

UPDATE:
Check Out Andy Popes code, a much better method of moving a userform with out a caption:

Here is some code to move the form around without the need for API coding.
Create a couple of private variables in the userform to remember the position when the left mouse button is pressed.

[vba]
Private m_sngX as single
Private m_sngY as singlePrivate Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = 1 Then
m_sngX = X
m_sngY = Y
End If
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = 1 Then

Me.Left = X + Me.Left – m_sngX
Me.Top = Y + Me.Top – m_sngY

End If
End Sub [/vba]
Orginal post

Yesterday I was playing around with Jan Karel Pieterse Watch Other Cell tool. I wanted to make the user form captionless and transparent. That’s easy enough to do but a problem arose. With the caption removed the form could not be moved.
One work around was to use the forms mouse move event and an API Call to hook the cursor location. Another API call is made to reposition the form. The Down and Up events are used to “turn on” weather or not we what to move the form. For the user it is much the same as a normal move process.

The API routines are included in the example file attached. If your thinking, “why not just use mouse X, Y and top and left?”, it’s because the API’s returns cursor position and will place the form with in your systems co-ordinate structure, not just excels. The results are more reliable.
There is one problem still outstanding with this method. When you first click the form to reposition it the form “jumps” to the places where you clicked the mouse. If it’s near the top left corner, then the result is hardly noticeable, it’s a different story down in the right hand corner. I think code could be written to correct for this but maybe you could simply put in an icon near the top left to allow the move?

Enjoy!
Moveable Captionless Userform

Programming to die for?

This is funny! i got 8 out of 10

Office and Vista Beta experience

In the past the beat experiences have been free, and quite good :-), sign up now, you’ve got nothing to lose!!!!

The new generation of Microsoft Windows© and Office© is about to be launched. Get in on the act right from the start and follow the new products as they go through to the finals. As a member of the Vista and Office Beta Experience you will benefit from valuable resources, specialist knowledge and additional bonus material. In addition, your subscription will include regular issues of the Beta Experience Newsletter containing specialist knowledge all about Windows Vista and Office “12″.

An Excel Front loader (Dot Net, dot slow! )

Now updated:
http://www.blog.methodsinexcel.co.uk/2006/05/02/excel-front-loader-v2/

Last night I jumped onto the .Net train. So I’m a little late?

I’m using VB 2005 express. I knocked up a little “front loader” app. Very simple, it makes a new excel instance and loads a .xls file called “App.xls” from the same dir into that excel instance then exits.

I had a number of problems:
The form does not display correctly (on my PC’s), and there does not seem to be a form.paint option I understand .Net handles this differently, I’m sure there’s a work round I just haven’t found it yet.
I wanted just to hide the form, but this didn’t work (frmLaod.visible = false), so I had to exit the app altogether.
I’m sure there are ways to do this, I just could find them!

Oh yes one other tinny thing, this is the slowest bit of software I have ever seen in my life!!!!, It’s a embarrassment, now that could just be my programme or it might not!

Here’s the .exe
Here the vb project