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!

Importing Data from Multiple Excel Columns 1

Status
Not open for further replies.

crabtreejames

Technical User
Nov 13, 2006
3
US
Through trial and error, combined with stealing every tidbit I could from this site, I've finally convinced Attachmate to read data from Excel. The downside to this pilfered knowledge is that I don't understand how to apply it to my actual needs. Specifically, how can I expand on what I have in order to import the data from column B? Specifically, the macro runs the same report multiple times and stores the results for downloading, but I want to be able to run reports that call for more than just the account number. What line(s) would I need to add to pull column B's data?

Here's my code:


Sub Main

Dim appExcel As Object
Dim wbExcel As Object
Dim aSheet As Object
Dim Sessions as Object
Dim System as Object
Dim AccountNum As String
Dim Sess0 as Object


Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions
Set Sess0 = System.ActiveSession

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If

Set AppExcel = CreateObject("Excel.Application")
If (System is Nothing) Then
Msgbox "Could not create the EXTRA System object. Stopping macro playback."
STOP
End If


Set wbExcel = AppExcel.WorkBooks.Open("C:\Program Files\ScriptTest.xls")
Set aSheet = wbExcel.Sheets("Datasheet")


Sess0.Screen.SendKeys("admin ba")
Sess0.Screen.Sendkeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop

For x = 1 to 1
AccountNum = aSheet.Cells(x,1).text
Sess0.Screen.Sendkeys("<Tab>")
Sess0.Screen.Sendkeys("<EraseEOF>")
Sess0.Screen.Sendkeys (AccountNum)
Sess0.Screen.Sendkeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop
Sess0.Screen.Sendkeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop
Sess0.Screen.Sendkeys("<Pf6>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop
Sess0.Screen.Sendkeys("<Tab>pc(r<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop
Sess0.Screen.Sendkeys("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop
Sess0.Screen.Sendkeys("<Pf3>")
Sess0.Screen.Sendkeys("<Pf3>")
Next

For x = 2 to aSheet.UsedRange.Rows.Count
AccountNum = aSheet.Cells(x,1).text
Sess0.Screen.Sendkeys("<EraseEOF>")
Sess0.Screen.Sendkeys("<Tab>")
Sess0.Screen.Sendkeys (AccountNum)
Sess0.Screen.Sendkeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop
Sess0.Screen.Sendkeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop
Sess0.Screen.Sendkeys("<Pf6>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop
Sess0.Screen.Sendkeys("<Tab>pc(a<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop
Sess0.Screen.Sendkeys("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0 : Loop
Sess0.Screen.Sendkeys("<Pf3>")
Sess0.Screen.Sendkeys("<Pf3>")

Next

Msgbox ("The macro has finished.")



Thanks in advance for any insight you can offer.
 
aSheet.Cells(x,1).text

The first item in a cell is the row. The second item in the cell is the column. Change 1 to 2 to get column B.
 
Well that's embarassingly simple. I'll try it out ASAP.

Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top