View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default problem in VB codes

There can be a difference between Me and the Activesheet--if you've
selected/activated a different sheet.



peyman wrote:

thanx Dave.so as I undrestand there is no difference between activesheet. ...
and Me. ...? right?

"Dave Peterson" wrote:

Me is a reserved word in VBA. It refers to the thing that owns the code. In
this case since the code is in a worksheet module, it refers to the worksheet
that owns the code.

You used activesheet. In some cases, you may be selecting or activating a
different sheet. I wanted to make sure that the correct sheet was printed, so I
used Me.

The other portion of the code is the application.ontime.

That just tells excel to wait a second (Now + TimeSerial(0, 0, 1)) and then
start a new routine.

You may want to take a look at Chip Pearson's notes:
http://www.cpearson.com/excel/OnTime.aspx



peyman wrote:

Dave.I didn't get what you did.can you please explain the codes you have
written.sorry I'm novice.what is "Me. ..."?what should I replace with that?

"Dave Peterson" wrote:

I tried adding some DoEvents. And it didn't help.

I tried toggling application.screenupdating off, then on. And it didn't help.

I tried adding application.wait (for a second). And it didn't help.

I tried adding minimizing the activewindow, then restoring it. And it didn't
help.

But this seemed to work ok for me.

Actually, I didn't test on paper. I only tested using print preview. But the
others failed with that. This one worked ok.

Option Explicit
Private Sub CommandButton11_Click()

Me.Range("G13:I32").Font.ColorIndex = xlAutomatic
Me.PrintOut preview:=True, Copies:=1, Collate:=True

If Me.OptionButton1.Value = True Then
Me.OptionButton2.Value = True
Else
Me.OptionButton1.Value = True
End If

Application.OnTime earliesttime:=Now + TimeSerial(0, 0, 1), _
procedu="'" & ThisWorkbook.Name & "'!" & Me.CodeName & ".WaitABit"

End Sub
Private Sub WaitABit()
Me.Range("G13:I32").Font.ColorIndex = 2
Me.PrintOut preview:=True, Copies:=1, Collate:=True
End Sub

(The WaitABit code is in the same worksheet module.)



peyman wrote:

hi,
I have a very simple code ,but I don't know why it doesn't work.

Private Sub CommandButton11_Click()
Range("G13:I32").Select
Selection.Font.ColorIndex = xlAutomatic
Range("B7").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
If ActiveSheet.OptionButton1.Value = True Then
ActiveSheet.OptionButton2.Value = True
Else
ActiveSheet.OptionButton1.Value = True
End If
Range("G13:I32").Select
Selection.Font.ColorIndex = 2
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub

the problem is when I run the program, the optionbutton toggle is not
showing in the second print?!!
Any help?thank you.

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson