OK. I'm back to this same problem. I actually managed to get the USGS program to work through VBA using sendKeys with the code below. Problem is, it wouldn't work without putting in the delay for each SendKey. Not only that, it is very sensitive to the timing which is based on how fast the computer its being run on opens and executes the USGS program. The program is downloadable freeware at
http://earthquake.usgs.gov/hazards/designmaps/javacalc.php
The VBA creates two batch files for the USGS program to work with; an input and an output file. If anyone can give me some ideas how to make this a little more solid and work without the delays I would greatly appreciate it. Thank you!!!
Sub getSeismic()
Dim siteClass As String
Dim iBatch As String
Dim oBatch As String
Dim latC As Double
Dim lonC As Double
Dim Ss As Double
Dim S1 As Double
Dim Ret As Long
Dim wbHi As Workbook
Dim wsSi As Worksheet
Dim wbHo As Workbook
Dim wsSo As Worksheet
'iBatch = "C:\Documents and Settings\eng48\My Documents\CTS Program\hazBatchi.xls"
'oBatch = "C:\Documents and Settings\eng48\My Documents\CTS Program\hazBatcho.xls"
With UserFormJobInfo
latC = .TextBox18.Value
lonC = .TextBox19.Value
siteClass = .ComboBox5.Value
End With
Application.Workbooks.Add
Set wbHi = Application.ActiveWorkbook
With wbHi
Set wsSi = wbHi.Sheets("Sheet1")
wsSi.Cells(2, 1).Value = latC
wsSi.Cells(2, 2).Value = lonC
wsSi.Cells(2, 3).Value = siteClass
.Save
iBatch = .Path
iBatch = iBatch & "\" & .Name
'MsgBox "Full Path name is " & iBatch
.Close
End With
Application.Workbooks.Add
Set wbHo = Application.ActiveWorkbook
With wbHo
.Save
oBatch = .Path & "\" & .Name
.Close
End With
Ret = fnShellOperation("M:\earthquake program\NSHMP_HazardApp.jar", "Open", SW_MAXIMIZE)
Application.Wait (Now + TimeValue("0:00:08"))
'AppActivate Ret, True
'MsgBox "Full Path Name is " & oBatch
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{ENTER}", True
Application.Wait (Now + TimeValue("0:00:02"))
SendKeys "{DOWN}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{DOWN}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{DOWN}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{RIGHT}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{RIGHT}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys iBatch, True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys oBatch, True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "{TAB}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "~", True
Application.Wait (Now + TimeValue("0:00:03"))
SendKeys "%{F4}", True
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys "~", True
Application.Workbooks.Open (oBatch)
Set wbHo = Application.ActiveWorkbook
Set wsSo = wbHo.Worksheets("Ss & S1 Values")
Ss = wsSo.Cells(ListRowN("Latitude (Degrees)", wsSo) + 1, 4)
S1 = wsSo.Cells(ListRowN("Latitude (Degrees)", wsSo) + 1, 5)
wbHo.Close
With UserFormJobInfo
.TextBox20.Value = Ss
.TextBox21.Value = S1
End With
End Sub