Copying data from webpage and pasting it in an Excel sheet

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jun 11, 2010 1:15 pm

I didn't have time to test these changes, but should get you going in the right direction again.

Maybe an explanation of how VBScript and Macro Scheduler interact will help here.

Basically VBScript is a completely separate programming language from the macro script language. Anything VBScript needs to be entirely within the VBStart and VBEnd statements. Macro script commands CANNOT be inside the VBStart/VBEnd.

Macro script commands execute first regardless of where the VBStart/VBEnd block is encountered in your code. The program contained within VBStart/VBEnd is only executed when a macro script statement of VBEval or VBRun is encountered.

So, your issues seemed to be that you mixed the statements up violating the rules I outlined above.

In my corrected code post I simply moved the macro script commands outside of the VBEnd statement where they belong.

If there are still issues, reply back and we'll go from there.

Good Luck.


Code: Select all

VBSTART
Dim xlApp

Sub CreateExcelObj
  Set xlApp = CreateObject("Excel.Application")
End Sub




Sub ExcelExample (mystring,myrange,myAddNew,mySave)

  Dim xlBook
  Dim xlSheet

  If (myAddNew = "True") THEN
    Set xLBook = xlApp.Workbooks.Open("c:\neteller saldo1.xlsx")
  Else
    Set xlBook = xlApp.ActiveWorkbook
  End if

  Set xlSheet = xlBook.Worksheets(1)

  xlApp.visible = True
  'optionally make the sheet visible
  'xlSheet.Application.Visible = True
  xlSheet.Range(myrange).Value = mystring

  'etc
  'If (mySave = "True") THEN
   ' xlSheet.SaveAs "c:\neteller saldo.xlsx"
  'End if
End Sub


Sub QuitExcel
  xlApp.Quit

  Set xlSheet = Nothing
  Set xlBook = Nothing
  Set xlApp = Nothing
End Sub

VBEND


//Get Web fields for user 1
//     code goes here
//Move the mouse cursor out of harm's way to avoid causing mouseover events to interrupt
MouseMove>0,0
Let>delay=1
IE_Create>0,IE[0]

// go to Neteller webpage
IE_Navigate>%IE[0]%,http://neteller.com/,r
IE_Wait>%IE[0]%,r
Wait>delay


// enter secure id
Let>FrameName={""}
Let>FormName={"signInform"}
Let>FieldName={"signInform:secureId"}
Let>FieldValue={"xxx"}
IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r

// enter password
Let>FrameName={""}
Let>FormName={"signInform"}
Let>FieldName={"signInform:password"}
Let>FieldValue={"xxx"}
IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r


// press submit
Let>FrameName={""}
Let>FormName={"signInform"}
Let>TagValue={"signInform:submit"}
IE_ClickTag>%IE[0]%,str:FrameName,str:FormName,INPUT,NAME,str:TagValue,r

IE_Wait>%IE[0]%,r
Wait>delay

WaitWindowOpen>money transfer*

wait>3

// get balance
//Modify buffer size if required ...
Let>SPAN12_SIZE=4098
IE_ExtractTag>%IE[0]%,,SPAN,12,0,SPAN12,r
MidStr>r_6,1,r,SPAN12


// get name
//Modify buffer size if required ...
Let>SPAN8_SIZE=4098
IE_ExtractTag>%IE[0]%,,SPAN,8,0,SPAN8,r
MidStr>r_6,1,r,SPAN8

// Closes the Neteller window
CloseWindow>Money Transfer & Online Payment | NETELLER - Client Account - Windows Internet Explorer



//
// Now save the fields to spreadsheet
VBRun>CreateExcelObj
VBRun>ExcelExample,SPAN12,A1,True,False
VBRun>ExcelExample,SPAN8,A2,False,False




//Get Web fields for user 2
//     code goes here

//Move the mouse cursor out of harm's way to avoid causing mouseover events to interrupt
MouseMove>0,0
Let>delay=1
IE_Create>0,IE[0]

// go to website
IE_Navigate>%IE[0]%,http://neteller.com/,r
IE_Wait>%IE[0]%,r
Wait>delay


// enter secure
Let>FrameName={""}
Let>FormName={"signInform"}
Let>FieldName={"signInform:secureId"}
Let>FieldValue={"xxx"}
IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r

// enter password
Let>FrameName={""}
Let>FormName={"signInform"}
Let>FieldName={"signInform:password"}
Let>FieldValue={"xxx"}
IE_FormFill>%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0,r


// press submit
Let>FrameName={""}
Let>FormName={"signInform"}
Let>TagValue={"signInform:submit"}
IE_ClickTag>%IE[0]%,str:FrameName,str:FormName,INPUT,NAME,str:TagValue,r

IE_Wait>%IE[0]%,r
Wait>delay

WaitWindowOpen>money transfer*

wait>3

// get balance
//Modify buffer size if required ...
Let>SPAN12_SIZE=4098
IE_ExtractTag>%IE[0]%,,SPAN,12,0,SPAN12,r
MidStr>r_6,1,r,SPAN12


// get name
//Modify buffer size if required ...
Let>SPAN8_SIZE=4098
IE_ExtractTag>%IE[0]%,,SPAN,8,0,SPAN8,r
MidStr>r_6,1,r,SPAN8

// Closes the Neteller window
CloseWindow>Money Transfer & Online Payment | NETELLER - Client Account - Windows Internet Explorer


VBRun>ExcelExample,SPAN12,C1,False,False

VBRun>ExcelExample,SPAN8,C2,False,True
//VBRun>QuitExcel


Label>end_script


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

Post by Marcus Tettmar » Fri Jun 11, 2010 1:23 pm

Macro script commands execute first regardless of where the VBStart/VBEnd block is encountered in your code. The program contained within VBStart/VBEnd is only executed when a macro script statement of VBEval or VBRun is encountered.
That's not quite true. Proof:

VBSTART
MsgBox "I'm here"
VBEND

MessageModal>And I'm here.

The code within the VBSTART/VBEND block is processed as soon as it is seen, so if before other code it will be processed before it.

What you might mean is that if your VBSTART/VBEND block just has subroutines or functions in it then those subroutines and functions are not "executed" until they are called with a VBRun or VBEval statement. That would be the case for a native subroutine too, as this is the nature of subroutines. They are "defined" but not executed until called.

But VBSTART/VBEND can contain code outside of a subroutine or function, in which case it will execute as soon as it is reached.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

brunop
Junior Coder
Posts: 38
Joined: Mon Dec 03, 2007 2:29 pm

Post by brunop » Sun Jun 13, 2010 1:02 pm

Thanks Adroege its running smoothly now and I have learned quite a bit about VBScripts and Scripting in general!

Ill probably end up with more questions later but then Ill start a new thread!

Thanks again

Bruno

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