Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

code line number

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GrannyM - 27 Feb 2008 18:53 GMT
Is there a way to retrieve the line number of the vba code itself?  Such as,
if an error occurs, throwing up a message box that says "Error at code line
173"
Tony Jollans - 27 Feb 2008 19:14 GMT
If you have line numbers in your code (not common these days) you could try
looking at Information.Erl

Signature

Enjoy,
Tony

> Is there a way to retrieve the line number of the vba code itself?  Such
> as,
> if an error occurs, throwing up a message box that says "Error at code
> line
> 173"
GrannyM - 27 Feb 2008 21:21 GMT
We are using Word 2003.  In the VBA module on the Standard Toolbar, it gives
you the line and col number of where your cursor is at in your code.   We
would like to be able to pull that line number into a variable.  To give you
a basic idea of what we want to do, we have hundreds of users and they expect
us to be omniscient and know everything without them giving us any
information.  We've tried creating  message boxes, but they tend to enter
right through them and then send us an email saying they had an error.  We
would like to create error trapping that will create an error log for our IT
Department that would give us some information to help track down the error.  
for example, something like: "UserName running macro 10-123 generated Error
Description at line #XX.  Variables at the time of the error were:  Variable
a = "1111", variable b = "", variable c  = "abc".

> If you have line numbers in your code (not common these days) you could try
> looking at Information.Erl
[quoted text clipped - 4 lines]
> > line
> > 173"
Tony Jollans - 27 Feb 2008 23:52 GMT
You can get that information if the users have "Allowed programmatic access
to the VBA project" (or whatever the option is called) but if they haven't
you will just generate another error.

You can't easily write a generic error trap that includes variables the way
you suggest (almost a mini dump) and if you are going to write specific
error traps and write a log with specific variables you probably have enough
information to hand without it.

Signature

Enjoy,
Tony

> We are using Word 2003.  In the VBA module on the Standard Toolbar, it
> gives
[quoted text clipped - 26 lines]
>> > line
>> > 173"
Karl E. Peterson - 28 Feb 2008 00:07 GMT
> We are using Word 2003.  In the VBA module on the Standard Toolbar, it gives
> you the line and col number of where your cursor is at in your code.   We
> would like to be able to pull that line number into a variable.

As Tony said, unless you add numbers to each line, no can do.

> To give you
> a basic idea of what we want to do, we have hundreds of users and they expect
> us to be omniscient and know everything without them giving us any
> information.

"Doesn't work," right?

> We've tried creating  message boxes, but they tend to enter
> right through them and then send us an email saying they had an error.

You could write a routine that timed how long the message box was up, and if they
dismissed it in under, say, a second, then pop it right back up there but double the
mandatory visible time.  Could be kind of a fun exercise in dealing with unruly
users, actually.  So fun, I just couldn't resist. <eg>

  Public Sub InTheirFace(ByVal TheMsg As String, ByVal MinSecs As Double)
     Dim Popped As Double
     Const OneSec As Double = 1 / 86400
     Do
        If Popped <> 0 Then MinSecs = MinSecs * 2
        Popped = CDbl(Now)
        MsgBox TheMsg, vbCritical, "In Your Face!"
     Loop Until (Popped + (OneSec * MinSecs)) < CDbl(Now)
  End Sub

You could call it with something like:

  Call InTheirFace("Report error code XYZ, luser!", 2)

> would like to create error trapping that will create an error log for our IT
> Department that would give us some information to help track down the error.
> for example, something like: "UserName running macro 10-123 generated Error
> Description at line #XX.  Variables at the time of the error were:  Variable
> a = "1111", variable b = "", variable c  = "abc".

Well, as Tony said, if you want the errorline, you'll need to supply it.
Signature

.NET: It's About Trust!
http://vfred.mvps.org

Tony Jollans - 28 Feb 2008 00:11 GMT
I really like that idea Karl!!

Signature

Enjoy,
Tony

>> We are using Word 2003.  In the VBA module on the Standard Toolbar, it
>> gives
[quoted text clipped - 45 lines]
>
> Well, as Tony said, if you want the errorline, you'll need to supply it.
Karl E. Peterson - 28 Feb 2008 00:33 GMT
>I really like that idea Karl!!

My old friend Alan Cooper would be rolling over in his grave, were he not still
alive. <lol>

>>   Public Sub InTheirFace(ByVal TheMsg As String, ByVal MinSecs As Double)
>>      Dim Popped As Double
[quoted text clipped - 5 lines]
>>      Loop Until (Popped + (OneSec * MinSecs)) < CDbl(Now)
>>   End Sub
Signature

.NET: It's About Trust!
http://vfred.mvps.org

GrannyM - 28 Feb 2008 13:06 GMT
Thanks guys.  That really does sound like fun.  I can just think of so many
things I'd like to put into that second message box that would probably get
me into a lot of trouble - if they actual read the box!

> > We are using Word 2003.  In the VBA module on the Standard Toolbar, it gives
> > you the line and col number of where your cursor is at in your code.   We
[quoted text clipped - 38 lines]
>
> Well, as Tony said, if you want the errorline, you'll need to supply it.
Karl E. Peterson - 28 Feb 2008 20:55 GMT
> Thanks guys.  That really does sound like fun.  I can just think of so many
> things I'd like to put into that second message box that would probably get
> me into a lot of trouble - if they actual read the box!

That's the spirit! <LOL>
Signature

.NET: It's About Trust!
http://vfred.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.