Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print number of documents with sendkeys

Status
Not open for further replies.

caerdydd

Programmer
Mar 2, 2004
35
GB
Hello
I'm trying to control the 'flaky' sendkeys to print a number of documents in VBA by using the kernel32 dll and the 'sleep' method set to 1sec gaps between each object. This is all being done in a client site product that uses vba.

My code is

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub CommandButton9_Clicked(ByVal EventData As TKoCommandButton.ClickedEventDataBag)
Dim Obj As Object
Set Obj = FlexSheet1.Frames
For Each Obj In FlexSheet1.Frames
Sleep 1000
SendKeys "^+{F12}", True
SendKeys "{ENTER}", True
Sleep 1000
FlexSheet1.SelectNextFrame
Next Obj
End Sub

when this runs it does not print all the objects, but just the last one. Does anyone know of a way around this so it will print all objects, from all frames. I'm thinking that i need to slow down the sendkeys operation becuase it does not seem to be able to keep up with the process. But not sure how to do this?
If i take out the for each statment so that there is only one object in one frame it prints no sweat.
Any ideas. Thanks in advance.
 
Set Obj = FlexSheet1.Frames
For Each Obj In FlexSheet1.Frames

Some inconsistency in the above 2 lines.
What is supposed to be Obj for you ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV thanks for the reply...i have amended the offending line. This is what i now have

Private Sub CommandButton9_Clicked(ByVal EventData As TKoCommandButton.ClickedEventDataBag)
Dim sht As FlexSheet1
Dim Obj As Object
Dim fme As Frame
Set Obj = SelectedFrame.ActiveControl.Object
For Each Obj In FlexSheet1.Frames

pause
FlexSheet1.SelectNextFrame
Next Obj
End Sub

Sub pause()
PauseTime = 1 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
print_graph
End
End Sub

Sub print_graph()
SendKeys "^+{F12}", True
SendKeys "{ENTER}", True
GoTo marker
End Sub

This allows me to print one object on my sheet as i click the button it finds the first object and then goes through the paus and print_graph sub routines. But i cannot get it back to the private sub to then loop through the remaining objects. As soon as the print_graph sub is done thats it all over. Does anyone have any idea how i can get back into the private routine code at the right place (flexsheet1.selectnextframe) so that it will loop through the rest of the objects.
very grateful for any suggestions.Rgds
 
ahhh..just deleted the 'end' statement from the pause sub routine.
But still can't get this to print all of the objects in the sheet. It does one and then the procedure ends.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top