VB macro works on XP, error on Win7

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Lorence
Newbie
Posts: 11
Joined: Mon Sep 24, 2007 12:34 am
Location: Ohio, USA
Contact:

VB macro works on XP, error on Win7

Post by Lorence » Wed Jul 02, 2014 3:50 pm

All,
I am converting my Macro Scheduler installation from WinXP to Win7 and have one final macro to move, but it is failing.
The macro uses VB code to open Internet Explorer, connect to an HP printer, change the paper Tray 1 paper size to Letter, the Tray 1 Type to Any, the Tray 2 Type to Letterhead, and the Tray 3 Type to Any.
This works perfectly on our WinXP installation of Macro Scheduler Version 13.2.4, but fails on Win7 with MS Version 14.1.05.
Below is the macro I'm currently using on the XP box. I based it on a macro that I obtained from one of the MJTNet forums.
Any suggestions/solutions are appreciated & welcome. I really want to shut down that XP box ASAP.

TIA,
Lorence Sing
Nationwide Children's Hospital
Columbus, Ohio
[email protected]
==================
remark> RunProgram>C:\Program Files\Internet Explorer\IEXPLORE.EXE 10.95.10.23/hp/device/this.LCDispatcher?update=html&cat=1&pos=0&menu=3.0&setMenu
VBSTART
Dim IE

Sub CreateIE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible=1
End Sub

Sub Navigate(URL)
IE.Navigate URL
do while IE.Busy
loop
End Sub

Sub KillIE
IE.Quit
Set IE = nothing
End Sub

Sub WebFormFill(fieldname,fieldvalue,submit)
Dim FormNr
Dim ItemNr
Dim TheForm

if IE.Document.All.Tags("FORM").Length = 0 then
MsgBox("No form found in page")
else
for FormNr = 0 to IE.Document.Forms.Length - 1
Set TheForm = IE.Document.Forms(FormNr)
for ItemNr = 0 to TheForm.Elements.Length - 1
if TheForm.Elements(ItemNr).Name = fieldname then
TheForm.Elements(ItemNr).Value = fieldvalue
If submit=1 then
TheForm.submit
end if
exit for
end if
next
next
end if
End Sub

'This function extracts text from a specific tag by name and index
'e.g. TABLE,0 (1st Table element) or P,1 (2nd Paragraph element)
'set all to 1 to extract all HTML, 0 for only inside text without HTML
Function ExtractTag(TagName,Num,all)
dim t
set t = IE.document.getElementsbyTagname(Tagname)
if all=1 then
ExtractTag = t.Item(Num).outerHTML
else
ExtractTag = t.Item(Num).innerText
end if
End Function

VBEND

VBRun>CreateIE
VBRun>Navigate,10.95.10.23/hp/device/this.LCDispatcher?update=html&cat=1&pos=0&menu=3.0&setMenu
Wait>5
remark>set the tray 1 size to Letter. The form's field name is 2004-ee4c-11d4-96-4e-0-10-83-cf-45-99, the value for Letter is 1.
VBRun>WebFormFill,2004-ee4c-11d4-96-4e-0-10-83-cf-45-99,1,0
remark>set the tray 1 type to Any. The form's field name is 2004-ee4c-11d4-96-4e-0-10-83-cf-45-99, the value for Any is 0.
VBRun>WebFormFill,2004-ee4c-11d4-96-4e-0-10-83-cf-45-99,0,0
remark>set the tray 2 type to Letterhead. The form's field name is 2005-ee4c-11d4-96-4e-0-10-83-cf-45-99, the value for Letterhead 3.
VBRun>WebFormFill,2005-ee4c-11d4-96-4e-0-10-83-cf-45-99,3,0
remark>set the tray 3 type to Any. The form's field name is 2006-ee4c-11d4-96-4e-0-10-83-cf-45-99, the value for Any is 0.
remark>The 1 at the end of this next command is the submit.
VBRun>WebFormFill,2006-ee4c-11d4-96-4e-0-10-83-cf-45-99,0,1
Wait>5
remark> Ask>All done - shall I close IE now?,r
remark> If>r=YES

VBRun>KillIE

remark> endif
==================
Lorence P. Sing, MT(ASCP)
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com

Lorence
Newbie
Posts: 11
Joined: Mon Sep 24, 2007 12:34 am
Location: Ohio, USA
Contact:

Re: VB macro works on XP, error on Win7

Post by Lorence » Wed Jul 02, 2014 3:52 pm

Sorry, I forgot to include the error message that I get on Win7:
the script appears to open IE, but give the following error 4 times:
:-2147023179
Line 26, Column 2

Then gives the following error twice:
:-2147023179
Line 17, Column 2

Then is seems to hang.

Thanks again,
Lorence Sing
Nationwide Children's Hospital
Columbus, Ohio
[email protected]
Lorence P. Sing, MT(ASCP)
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: VB macro works on XP, error on Win7

Post by Marcus Tettmar » Wed Jul 02, 2014 4:30 pm

Might be to do with the version of IE and the difference in the way the html is rendered. Any chance you can post an attachment for your script instead.

And is there any reason you are using that old VBScript instead of the built in WebRecorder/IE functions?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Lorence
Newbie
Posts: 11
Joined: Mon Sep 24, 2007 12:34 am
Location: Ohio, USA
Contact:

Re: VB macro works on XP, error on Win7

Post by Lorence » Thu Jul 03, 2014 12:07 pm

Good morning, Marcus.

I've attached the .scp file that I'm using.
I did try the recorder, but I was trying to avoid mouse positioning, I would much prefer the specificity and readability of the VB script, We can tell exactly what it is doing. The recorder's use of mouse movement is far too ambiguous - it the IE window isn't opened properly, if the resolution of the screen changes, any of those things can case failure of the script.

Thanks for any suggestions or help,
Lorence
Lorence P. Sing, MT(ASCP)
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: VB macro works on XP, error on Win7

Post by Marcus Tettmar » Thu Jul 03, 2014 1:21 pm

I didn't mention the macro recorder. We're at cross purposes. I think you are confusing WebRecorder and the IE funtions with the basic keyboard/mouse macro recorder.

WebRecorder does not rely on positioning. It looks under the skin of IE and accesses html objects directly via IE's Document Object Model. You can use WebRecorder and/or the IE Find Element Wizard to simplify the coding. They help you identify the elements. Neither use screen positions in any way shape or form.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Lorence
Newbie
Posts: 11
Joined: Mon Sep 24, 2007 12:34 am
Location: Ohio, USA
Contact:

Re: VB macro works on XP, error on Win7

Post by Lorence » Thu Jul 03, 2014 2:47 pm

I think that you are correct - I'd forgotten that there were two recorders, I'll look at the Web recorder after my meetings.
Thanks for the guidance, Marcus.

Lorence
Lorence P. Sing, MT(ASCP)
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts