View Single Post
  #24   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's an added .ontime line in the WaitABit changed procedure that calls
waitabit2.

And WaitABit2 is the procedure where you'd print the 3rd time.

peyman wrote:

I'm confused.which line should I add to the "waitabit" procedure?and what's
the "waitabit2"?

"Dave Peterson" wrote:

I'd add another delayed procedure in the WaitABit procedure.

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

'toggle your commandbutton value here!

'and call another procedure
Application.OnTime earliesttime:=Now + TimeSerial(0, 0, 1), _
procedu="'" & ThisWorkbook.Name & "'!" & Me.CodeName & ".WaitABit2"
End Sub
Private Sub WaitABit2()
'do your setup and print here
End Sub

peyman wrote:

hi Dave,
I removed preview:=true and it works fine.how about if wanna repeat the
second print with toggled optionbutton?in other words, I'd like to have one
print with ColorIndex = xlAutomatic (no matter what optionbutton is selected)
and two more prints with different optionbutton selected.now I have only two
of them.thanx again

"Dave Peterson" wrote:

You should be clicking on CommandButton11. Is that what you meant by the
"print" button?

peyman wrote:

hi Dave,
I used your code :
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

it works perfect but still a bit manual.I have push the "print" button.can't
it be done automatically??

"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


--

Dave Peterson


--

Dave Peterson