appactivate

P

Philip Kopf

I have tried to use the appactivate command but can not
get the focus back to excel after I gather info from
another application. Attached is my code. Can anyone
tell me how to get excel back on top?

Private Sub CommandButton2_Click()
'
Dim ACAD As Object
Dim MS As Object
Dim myappid
Set ACAD = GetObject(, "AUTOCAD.APPLICATION")
Set MS = ACAD.activedocument.ModelSpace
AppActivate "autodesk"
'
Dim llpc As Variant
Dim urpc As Variant
Dim htft, htin, wdft, wdin
'
With ACAD.activedocument.Utility
llpc = .GetPoint(, vbCr & "Pick the Lower Left
Panel Corner: ")
urpc = .GetPoint(llpc, vbCr & "Pick the Upper
Right Panel Corner: ")
End With
'
With Worksheets("A")
'
'
.Range("c22").Value = 0
.Range("d22").Value = 0
.Range("c21").Value = 0
.Range("d21").Value = 0
'
wdft = Application.WorksheetFunction.RoundDown
((urpc(0) - llpc(0)) / 12, 0)
wdin = (urpc(0) - llpc(0)) - (wdft * 12)
htft = Application.WorksheetFunction.RoundDown
((urpc(1) - llpc(1)) / 12, 0)
htin = (urpc(1) - llpc(1)) - (htft * 12)
'
.Range("c21").Value = htft
.Range("d21").Value = htin
.Range("c22").Value = wdft
.Range("d22").Value = wdin
'
End With
AppActivate "Microsoft Excel"
End Sub
 
T

Tom Ogilvy

Why appactivate Autocad in the first place. Does your code fail if you
remove that line.
 
P

Philip Kopf

Because it is the other application that I am gtathering
data from and it requires me to appactivate it so I can
see it to dynamically get some dimensional data from
Autocad. Once I get that data I am writing it back to
excel. Then I want to have excel do some other work for
me. But I can't get the excel spreadsheet back on top.
 
T

Tom Ogilvy

Usually that is not the case for code ( unless you mean you must physically
see it on your screen so you can personally manually record some data)

The best would be to comment out the line and see if it still works.

If you find you must have it, and appactivate for excel doesn't work, then I
guess you will have to try the windows API.

Check out this post for information:

http://groups.google.com/groups?threadm=OgCCVl4vBHA.1592@tkmsftngp07
 
G

Guest

For this case I actually need to physically see the
screen in the other application. Thanks for the help...
 
Top