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!

Run a macro only if in the correct screen in Extra!

Status
Not open for further replies.

Losman500

Technical User
Oct 9, 2007
43
US
First off I'd like to thank everyone in this FORUM who have helped make our job much easier.

I'm new at this, but I need help figuring out how to run a macro only if the user is on the correct Extra screen. The way the macro is triggered is by using a tool bar button, which scrapes information from EXTRA and puts it in an Excel form.

I need the macro to look at a specific screen position (1, 2, 4) and if the value = XXXX then continue to run the macro otherwise stop and display an error message "you must be in XXXX screen to run macro"

I wasn't able to find a useful thread for this need yet.
Here's my code so far:

Code:
Sub Main
 Dim Session As Object
 Dim Sess0 As Object
 Dim System As Object
 Set System = CreateObject("Extra.system")
 If (System Is Nothing) Then
 MsgBox "Could not Create Session"
 Stop
 End If
 Set Session = System.Sessions
 Set Sess0 = System.Activesession
 Dim ObjExcel As Object
 Dim ObjWorkbook As Object
 Dim ObjChart as Object
  
 Set ObjExcel = CreateObject("Excel.Application.11")
 objExcel.Visible=True
 Set ObjWorkbook = objExcel.Workbooks.Open("C:RA sheet.xls")
 
 result = Sess0.Screen.GetString(2, 73, 8)
 ObjWorkbook.Worksheets("Sheet1").Cells(10, 3).Value = result  'SO Number
 
 result = Sess0.Screen.GetString(15, 19, 24)
 ObjWorkbook.Worksheets("Sheet1").Cells(10, 5).Value = result  'Part Number
 
 result = Sess0.Screen.GetString(15, 65, 13)
 ObjWorkbook.Worksheets("Sheet1").Cells(10, 8).Value = result  'Serial/RT
 
 result = Sess0.Screen.GetString(14, 5, 2)
 ObjWorkbook.Worksheets("Sheet1").Cells(10, 9).Value = result  'Quantity
  
End Sub
 
Code:
' Untested

Sub Main()
   Dim Sys As Object, Sess As Object

   Set Sys = CreateObject("Extra.System")

   If Sys Is Nothing Then
      MsgBox ("Could not create Extra.System...is E!PC installed on this machine?")
      Exit Sub
   End If

   Set Sess = Sys.ActiveSession

   If Sess Is Nothing Then
      MsgBox ("No session available...stopping macro playback.")
      Exit Sub
   End If

   [COLOR=red]If UCase(Sess.Screen.GetString(1, 2, 4)) = "XXXX" Then[/color]
      Dim ObjExcel As Object, ObjWorkbook As Object, ObjWorksheet As Object, result As String

      Set ObjExcel     = CreateObject("Excel.Application")
      Set ObjWorkbook  = ObjExcel.Workbooks.Open("C:[COLOR=red]\[/color]RA sheet.xls")
      Set ObjWorksheet = ObjWorkbook.Sheets("Sheet1")
      ObjExcel.Visible = True

      result = Sess.Screen.GetString(2, 73, 8)
      ObjWorksheet.Cells(10, 3).Value = result  ' SO Number

      result = Sess.Screen.GetString(15, 19, 24)
      ObjWorksheet.Cells(10, 5).Value = result  ' Part Number

      result = Sess.Screen.GetString(15, 65, 13)
      ObjWorksheet.Cells(10, 8).Value = result  ' Serial/RT

      result = Sess.Screen.GetString(14, 5, 2)
      ObjWorksheet.Cells(10, 9).Value = result  ' Quantity

      ObjWorkbook.Save
      ObjWorkbook.Close
      ObjExcel.Quit
         
      Set ObjWorksheet = Nothing
      Set ObjWorkbook  = Nothing
      Set ObjExcel     = Nothing
   [COLOR=red]Else[/color]
      MsgBox "You must be in XXXX screen to run macro."
   [COLOR=red]End If[/color]

   Set Sess = Nothing
   Set Sys  = Nothing
End Sub
 
Thank you very much, this has really helped me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top