View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Displayalerts not working

In the VBE go to the View menu and click Immediate window so it has a check
next to it. It will appear as another window in the VBE.

Debug Print
outputs to the immediate window. It is just another debugging tool. You
can also type a complete VBA statement in it and hit enter and it will
immediately execute

For instance, If I wanted to delete all shapes on my worksheet, but didn't
want to select them all, I could go to the immediate window in the VBE and
type

Activesheet.Shapes.SelectAll : Selection.Delete

and hit enter. and it would clear my sheet.

It is also good for testing in complex strings where you are concatenating
variables. For example, I just posted this. (which I copied from the
immediate window)

arr = Array("My","Your")
i = 1
? arr(i)
Your
set cntRef = Range("A1:A10")
set cntRef2 = Range("B1:B10")
? "=SUMPRODUCT(--('" & Arr(i) & _
"Billable FT'!" & CntRef.Address & """0""),--('" & Arr(i) & _
"Billable FT'!" & CntRef2.Address & "))"
=SUMPRODUCT(--('YourBillable FT'!$A$1:$A$10"0"),--('YourBillable
FT'!$B$1:$B$10))


first I had to create some variables to simulate what the poster was doing.
so I created an array with

arr = Array("My","Your")

then I assigned a value to the variable i

i = 1

In each case I typed those in and hit enter.

Then I wanted to see what was stored in arr(i) so I did
? arr(i)
and hit enter. It returned Your (the array is zero based).

Eventually I tested the string concatenation with the variables to see if it
produced the desired string.

It appears to.

So that was just as an example.

--
Regards,
Tom Ogilvy





"Hari" wrote in message
...
Hi Tom and Norman,

Your "creates a new variant variable and assigns it a value." is a superb
one. Its crystal clear for me now.

Actually I ran Norman's and your code and ( my VBE was not set to option
explicit and hence did not get any compile error , variable not defined --
now, I have changed my settings to require variable definition - thanx for
that too) I did not get any output of debug.print.

Is debug.print supposed to show me some result/output. Is it similar to
msgbox. I got no messageboxes saying "DisplayAlerts is a String with a
value of Funny Bunny. Neither do i get anything called "Opening State

True"
etc.

I thought debug.print might have fired off printouts (hard copies) to my
printer (a big fool am!!) but found no such printouts.

Before doing the above I consulted VBA help but couldnt understand the

terse
description "The Debug object sends output to the Immediate window at
runtime."
When i click on the runtime blue link above I get a message saying "A run
time error has occurred, do you wish to debug"

--
Thanks a lot,
Hari
India
"Tom Ogilvy" wrote in message
...
Norman didn't talk about what displayalerts is.

Sub TesterAA()

Debug.Print "Opening State", Application.DisplayAlerts
DisplayAlerts = False
Debug.Print "After DisplayAlerts = False command", _
Application.DisplayAlerts
DisplayAlerts = "Funny Bunny"
Debug.Print "DisplayAlerts is a " & _
TypeName(DisplayAlerts) & " with a value of " & _
DisplayAlerts
DisplayAlerts = True
Debug.Print "Closing State", Application.DisplayAlerts

End Sub

produces:

Opening State True
After DisplayAlerts = False command True
DisplayAlerts is a String with a value of Funny Bunny
Closing State True

---------

so displayalerts = "anything" creates a new variant variable and assigns

it
a value.

If you put

Option Explicit

at the top of the module and compile, you will be notified that
DisplayAlerts is undefined.

--
Regards,
Tom Ogilvy

"Norman Jones" wrote in message
...
Hi Hari,

Try runnining this small demo:

Sub Tester()
Debug.Print "Opening State", Application.DisplayAlerts
DisplayAlerts = False
Debug.Print "After DisplayAlerts = False command", _
Application.DisplayAlerts

DisplayAlerts = True
Debug.Print "Closing State", Application.DisplayAlerts

End Sub

The immediate window reports:


Opening State True
After DisplayAlerts = False command True
Closing State True

As you see, if DisplayAlerts is used without the required Application
qualifier, no error is observed but neither is any response.

That is why Excel was throwing up the overwrite alert message. If you

rerun
the code (using the qualified construct), no alert should be observed.

For the record, I have not run your code or otherwise examined it. I

did,
however, run a test repoducing a file overwrite event.

---
Regards,
Norman



"Hari" wrote in message
...
Hi Norman,

Just from understanding point of view....

When I previously wrote it as -- DisplayAlerts = True -- how does

excel
interpret the statement. Is NOT writing Application. NOT considered

as
an
error. Does that mean DisplayAlerts = True is also a valid statement

on
its
own and if so what does it do.

Thanks a lot,
Hari
India

"Norman Jones" wrote in message
...
Hi Hari,

Just to add, you would similarly need to amend the closing:

DisplayAlerts = True

to

Application. DisplayAlerts = True


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Hari,

Try changing:


DisplayAlerts = False

to

Application. DisplayAlerts = False


---
Regards,
Norman