Skip to Content
-1

At end of script new Print dialog box open. I want to automate please suggest code

Aug 28, 2017 at 11:40 AM

173

avatar image
Former Member

The above dialog box open

I want to automate through Excel VBA Script

Please suggest code.

sap.jpg (35.8 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Best Answer
Script Man Aug 30, 2017 at 07:30 AM
1

Hi Pavan,

I did use this workaround for years.

Regards,

ScriptMan

set Wshell = CreateObject("WScript.Shell")
Do 
 bWindowFound = Wshell.AppActivate("Print")
 WScript.Sleep 1000
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Print")
if (bWindowFound) Then
  Wshell.appActivate "Print"
  WScript.Sleep 100
  Wshell.sendkeys "{ENTER}"
end if
bWindowFound = Wshell.AppActivate("Print")
if (bWindowFound) Then
  Wshell.appActivate "Print"
  WScript.Sleep 100
  Wshell.sendkeys "{TAB}{ENTER}"
end if
bWindowFound = Wshell.AppActivate("Print")
if (bWindowFound) Then
  Wshell.appActivate "Print"
  WScript.Sleep 100
  Wshell.sendkeys "{TAB}{TAB}{ENTER}"
end if
on error resume next
session.findById("wnd[1]").close
on error goto 0
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Dear sir

Program is debug on below line and show Run time error as below

please suggest

capture.png (9.8 kB)
0
Script Man Sep 07, 2017 at 01:26 PM
0

Hi Pavan,

the above solution was only for VBS. The solution below can also be used for VBA.

Regards,

ScriptMan

Set wshell = CreateObject("WScript.Shell")
Do
 bWindowFound = wshell.AppActivate("Print")
 'WScript.Sleep 1000
 wshell.Run "c:\tmp\sleep.vbs" & " 1000", 0, True
Loop Until bWindowFound
bWindowFound = wshell.AppActivate("Print")
If (bWindowFound) Then
  wshell.AppActivate "Print"
  'WScript.Sleep 100
  wshell.Run "c:\tmp\sleep.vbs" & " 100", 0, True
  wshell.SendKeys "{ENTER}"
End If
bWindowFound = wshell.AppActivate("Print")
If (bWindowFound) Then
  wshell.AppActivate "Print"
  'WScript.Sleep 100
  wshell.Run "c:\tmp\sleep.vbs" & " 100", 0, True
  wshell.SendKeys "{TAB}{ENTER}"
End If
bWindowFound = wshell.AppActivate("Print")
If (bWindowFound) Then
  wshell.AppActivate "Print"
  'WScript.Sleep 100
  wshell.Run "c:\tmp\sleep.vbs" & " 100", 0, True
  wshell.SendKeys "{TAB}{TAB}{ENTER}"
End If
bWindowFound = wshell.AppActivate("Print")
While (bWindowFound)
  'WScript.Sleep 500
  wshell.Run "c:\tmp\sleep.vbs" & " 500", 0, True
  bWindowFound = wshell.AppActivate("Print")
Wend
On Error Resume Next
session.findById("wnd[1]").Close
On Error GoTo 0

. . . 


sleep.vbs in c:\tmp:

set args = wscript.arguments
if args.count>0 then
   Wscript.Sleep WScript.Arguments(0)
else
 Wscript.Sleep 1000
end if

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Dec 16, 2017 at 03:19 PM
0

Thank you

Very much

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jan 30 at 07:14 AM
0

set Wshell = CreateObject("WScript.Shell")
Do 
 bWindowFound = Wshell.AppActivate("Print")
 WScript.Sleep 1000
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Print")
if (bWindowFound) Then
  Wshell.appActivate "Print"
  WScript.Sleep 100
  Wshell.sendkeys "{ENTER}"
end if
bWindowFound = Wshell.AppActivate("Print")
if (bWindowFound) Then
  Wshell.appActivate "Print"
  WScript.Sleep 100
  Wshell.sendkeys "{TAB}{ENTER}"
end if
bWindowFound = Wshell.AppActivate("Print")
if (bWindowFound) Then
  Wshell.appActivate "Print"
  WScript.Sleep 100
  Wshell.sendkeys "{TAB}{TAB}{ENTER}"
end if
on error resume next
session.findById("wnd[1]").close
on error goto 0
base on your script, i would like to change numbers of copie?

Can you help me, ScriptMan?

Share
10 |10000 characters needed characters left characters exceeded
Script Man Mar 15 at 11:28 AM
0

I'm sorry, but I only accidentally saw the question today.

But you have to find out beforehand about which hotkey the number of copies can be jumped to. When the window appears at the manual call and is in the foreground, press the ALT key. At this moment a letter is underscored and this must be taken. Unfortunately, I work with a German version and can not test it here.

My suggestion:

 set Wshell = CreateObject("WScript.Shell")
Do 
 bWindowFound = Wshell.AppActivate("Print")
 WScript.Sleep 1000
LoopUntil bWindowFond
bWindowFound = Wshell.AppActivate("Print")
if(bWindowFound)Then
  Wshell.appActivate "Print"
  WScript.Sleep 100
  Wshell.sendkeys "%n" 'or u,m,b,e,r...
  WScript.Sleep 100
  Wshell.sendkeys "2"
  WScript.Sleep 100
  Wshell.sendkeys "{TAB}"
  WScript.Sleep 100
  Wshell.sendkeys "{ENTER}"
end if
. . .

Regards,

ScriptMan

Share
10 |10000 characters needed characters left characters exceeded