Is there a way to use a variable in the get cell function, so that I can access data contained in a row specified by the user in an edit box?
I tried the following, but receive a runtime error 1004
let>r=dialog1.msedit
VBEval>GetCell("Sheet2",r,1),fleet
If I specify the row, everything works fine
GetCell("Sheet2",2,1)
Any help would be appreciated thanks
VBSTART
Dim xlApp
Dim xlBook
'Opens the Excel file in Excel
Sub OpenExcelFile(filename)
Set xlApp = CreateObject("Excel.Application")
xlApp.visible = true
Set xlBook = xlApp.Workbooks.open(filename)
end sub
'Use this to close Excel later
Sub CloseExcel
xlApp.quit
Set xlApp = Nothing
End Sub
'Retrieves a cell value from the specified
'worksheet
Function GetCell(Sheet,Row,Column)
Dim xlSheet
Set xlSheet = xlBook.Worksheets(Sheet)
GetCell = xlSheet.Cells(Row,Column).Value
End Function
'Sets specified cell of specified worksheet
Function SetCell(Sheet,Row,Column,NewValue)
Dim xlSheet
Set xlSheet = xlBook.Worksheets(Sheet)
xlSheet.Cells(Row,Column).Value = NewValue
End Function
VBEND
Dialog>Dialog1
Caption=AMT ENTRY
Width=391
Height=300
Top=220
Left=501
Max=1
Min=1
Close=1
Resize=1
CheckBox=msCheckBox1,New Event,96,65,179,False
CheckBox=msCheckBox2,New Task,96,90,218,False
Label=Select Entry Type,96,40,true
Button=Enter,96,200,75,25,1
Button=Cancel,208,200,75,25,2
label=Excel Line Number:,96,130,true
Edit=msEdit,190,125,25,3
label=Wait Time Factor:,96,160,true
Edit=msEdit2,190,155,25,1
EndDialog>Dialog1
Let>Message=3
let>k=0
Repeat>k
Let>Message=Message+1
Let>dialog1.msbutton1=Enter
Let>dialog1.msbutton2=Cancel
Let>dialog1.mslabel1=Select Entry Type
Let>dialog1.mslabel2=Excel Line Number:
Let>dialog1.msedit=%Message%
Let>dialog1.msedit2=1
Let>dialog1.mslabel3=Wait Time Factor:
ResetDialogAction>dialog1
Show>dialog1,res1
let>ExcelLine=dialog1.msedit+1
If>res1=1
If>dialog1.msCheckbox1=True
If>dialog1.msCheckbox2=True
Message>Error: Only one entry may be selected at a time
Let>Message=Message-1
endif
If>dialog1.msCheckbox2=False
let>r=dialog1.msedit
VBRun>OpenExcelFile,C:\Auto\AMTtest.xls
VBEval>GetCell("Sheet2",r,1),fleet
VBEval>GetCell("Sheet2",r,2),plant
VBEval>GetCell("Sheet2",r,3),description
VBEval>GetCell("Sheet2",r,4),component
VBEval>GetCell("Sheet2",r,5),modifier
VBEval>GetCell("Sheet2",r,6),tasktype
VBEval>GetCell("Sheet2",r,7),taskstatus
VBEval>GetCell("Sheet2",r,8),source
VBEval>GetCell("Sheet2",r,9),symptom
VBEval>GetCell("Sheet2",r,10),cause
VBEval>GetCell("Sheet2",r,11),jobcode
VBEval>GetCell("Sheet2",r,12),failuretype
VBEval>GetCell("Sheet2",r,13),planned
VBEval>GetCell("Sheet2",r,14),actual
VBEval>GetCell("Sheet2",r,15),eventcondition
VBEval>GetCell("Sheet2",r,16),eventstatus
VBEval>GetCell("Sheet2",r,17),dayplandown
VBEval>GetCell("Sheet2",r,18),monthplandown
VBEval>GetCell("Sheet2",r,19),yearplandown
VBEval>GetCell("Sheet2",r,20),hourplandown
VBEval>GetCell("Sheet2",r,21),minuteplandown
VBEval>GetCell("Sheet2",r,22),dayactualdown
VBEval>GetCell("Sheet2",r,23),monthactualdown
VBEval>GetCell("Sheet2",r,24),yearactualdown
VBEval>GetCell("Sheet2",r,25),houractualdown
VBEval>GetCell("Sheet2",r,26),minuteactualdown
VBEval>GetCell("Sheet2",r,27),dayplanup
VBEval>GetCell("Sheet2",r,28),monthplanup
VBEval>GetCell("Sheet2",r,29),yearplanup
VBEval>GetCell("Sheet2",r,30),hourplanup
VBEval>GetCell("Sheet2",r,31),minuteplanup
VBEval>GetCell("Sheet2",r,32),dayactualup
VBEval>GetCell("Sheet2",r,33),monthactualup
VBEval>GetCell("Sheet2",r,34),yearactualup
VBEval>GetCell("Sheet2",r,35),houractualup
VBEval>GetCell("Sheet2",r,36),minuteactualup
VBEval>GetCell("Sheet2",r,37),numberofallocations
VBEval>GetCell("Sheet2",r,38),reason1
VBEval>GetCell("Sheet2",r,39),activity1
VBEval>GetCell("Sheet2",r,40),cause1
VBEval>GetCell("Sheet2",r,41),responsibility1
VBEval>GetCell("Sheet2",r,42),reason2
VBEval>GetCell("Sheet2",r,43),activity2
VBEval>GetCell("Sheet2",r,44),cause2
VBEval>GetCell("Sheet2",r,45),responsibility2
VBEval>GetCell("Sheet2",r,46),actualhours2
VBRun>CloseExcel
Let>t=dialog1.msedit2
let>w=.05/t
let>x=.25/t
let>y=.5/t
let>z=1/t
wait>y
FindImagePos>c:\auto\RemoteDesktop.bmp,SCREEN,0,1,X,Y,n
If>n>0
MouseMove>X_0,Y_0
Lclick
Endif
MouseMove>17,74
Lclick
wait>w
Let>WSI_TIMEOUT=3
WaitScreenImage>C:\Auto\waitforaddevent.bmp,0
//fleet clear
MouseMove>982,452
Lclick
wait>x
//fleet text field
MouseMove>785,452
Lclick
wait>x
Send>fleet
wait>z
//fleet ...
MouseMove>965,452
Lclick
wait>x
//plant clear
MouseMove>982,484
Lclick
wait>x
//plant text field
MouseMove>785,484
Lclick
wait>x
Send>plant
wait>z
//plant ...
MouseMove>965,484
Lclick
wait>x
// >>Button
MouseMove>997,720
Lclick
wait>y
Let>WSI_TIMEOUT=y
WaitScreenImage>C:\Auto\newevent.bmp,0
///////////////rest of remote desktop stuff removed...works fine
endif
endif
If>dialog1.msCheckbox2=True
mousemove>1900,0
/////////////////more stuff removed
endif
endif
If>res1=2
let>k=1
endif
Until>k=1
Using a variable in get cell function?
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 2
- Joined: Sat May 30, 2009 8:22 am
- Location: Perth AU
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Sure. Put the variable in %..% symbols:
VBEval>GetCell("Sheet2",%r%,19),yearplandown
VBEval>GetCell("Sheet2",%r%,19),yearplandown
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 2
- Joined: Sat May 30, 2009 8:22 am
- Location: Perth AU