Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error getting the value from excel

Status
Not open for further replies.

link99sbc

Technical User
Apr 8, 2009
141
US
trying to loop through worksheet.
value of colA in one location and value of colB
goes in another location in extra.
I'm not getting the syntax correct.

Dim xlApp As Object, xlSheet As Object, MyRange As Object
Set xlApp = CreateObject("excel.application")
xlApp.Application.DisplayAlerts = False 'Turn off Warning Messages'
xlApp.Visible = True
xlApp.Workbooks.Open FileName:="C:\Book2.xls"
Set xlSheet = xlApp.activesheet
Set MyRange = xlApp.activesheet.Range("A:B")


Dim Row As Long
With xlApp.ActiveSheet
Set MyRange = .Range("A1:B65536").Resize(xlApp.CountA(.Range("A1:B65536")))

For Row = 1 To MyRange.Rows.Count
Sess0.Screen.PutString MyRange.(A).Value, 4, 18
Sess0.Screen.SendKeys "<ENTER>"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.PutString MyRange.(B).Value, 21, 13
Sess0.Screen.SendKeys "<ENTER>"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
End With
Next Row



End Sub
 


Hi,
Code:
    Dim xlApp As Object, xlSheet As Object, MyRange As Object
    
    '[b]this is the Excel Application Object[/b]
    Set xlApp = CreateObject("excel.application")
    xlApp.DisplayAlerts = False 'Turn off Warning Messages'
    xlApp.Visible = True
    xlApp.Workbooks.Open Filename:="C:\Book2.xls"
    
    '[b]this is the sheet Object[/b]
    Set xlSheet = xlApp.ActiveSheet
    
    '[b][red]Row[/red] is a RESERVE WORD[/b]
    Dim lRow As Long
    With xlSheet
       Set MyRange = .Range("A1:B65536").Resize(xlApp.CountA(.Range("A1:B65536")))
    
    For lRow = 1 To MyRange.Rows.Count
    
    '[b]this is the cell object within the defined range[/b]
       Sess0.Screen.PutString MyRange.Cells(lRow, 1), 4, 18
       Sess0.Screen.SendKeys "<ENTER>"
       Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
    
       Sess0.Screen.PutString MyRange.Cells(lRow, 2).Value, 21, 13
       Sess0.Screen.SendKeys "<ENTER>"
       Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
       End With
    Next Row

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I took off row and left next and it work ok now Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top