• Not Answered

Print out charts from Process History view via VBA

Dear Engineers,

I need to print a specific chart at the end of the production time.

Now the Operator click on a button, the specific trend is generated via script, for exemple   Call Shell("CHS aPBL_AI_FP.phve /sub R321TT100 /starttime (27/01/16 08:00:00 ) /endtime (27/01/16 14:00:00 )").

That works fine... but the operator needs to Click on "Print" on Process HV.

My question: Is it possible to add a command line in my script to print automatically the chart without a second mouse click.

Tank you.

Regards.

3 Replies

  • You could try:

    Private Sub PrintButton_Click()

    Dim CHSWindow as Double
    Dim PauseTime as Integer
    Dim StartTime as Variant

    ' Open Trendwindow and get 'Handle'
    CHSWindow = Shell("CHS aPBL_AI_FP.phve /sub R321TT100 /starttime (27/01/16 08:00:00 ) /endtime (27/01/16 14:00:00 )")
    ' Now wait to build up

    StartTime = Timer
    PauseTime = 20 ' Adjust to the time necessary to build up the trend
    Do While Timer < StartTime + PauseTime ' No wait-function in VB.....
    DoEvents ' Allow other applications to do their work
    Loop

    AppActivate CHSWindow
    SendKeys "%F{DOWN 7}{ENTER}", TRUE 'this should show the print dialog from the File-menu ("^P" doesn't work...)

    ' Now wait to build up the print dialog
    StartTime = Timer
    PauseTime = 2 ' Adjust to the time necessary to build up the print dialog
    Do While Timer < StartTime + PauseTime '
    DoEvents ' Allow other applications to do their work
    Loop

    AppActivate CHSWindow
    SendKeys "{ENTER}", TRUE 'this should be the response to the print dialog

    ' Now wait to print the first page
    StartTime = Timer
    PauseTime = 2 ' Adjust to the time necessary
    Do While Timer < StartTime + PauseTime '
    DoEvents ' Allow other applications to do their work
    Loop

    AppActivate CHSWindow
    SendKeys "{ESC}", TRUE 'this should be the response to the second print dialog
    SendKeys "%{F4}", TRUE 'Close the trend window

    End Sub

    You have to experiment with the times for window-buildup and see whether you get the correct responses.
    This is just a first approach and could be optimised.
    Error handling is not included, and should be.
    Good luck!
  • In reply to Maarten van der Waal:

    Hello Maarten,
    thank you for your solution I will try this!
    I'm a bit "afraid" of, what will happen if the operator click faster, than the "SendKey".
    Regards
  • In reply to Maarten van der Waal:

    hi Maarten

    The code you provided is very helpful for us.
    But we need to change the title and subtitle of trend chart dynamically via VBA
    Do you know the variables of title or subtitle in PAS system such as starttime is the variable of Start time, endtime is the variable of End time?
    I have checked the help of PAS on line book (Customing the Process History View section), and can't find any information about it.
    Thank you in advanced.