PDA

View Full Version : Solved: Activate next cell ?



omnibuster
01-04-2009, 07:11 AM
Why the code dont activate Range ("A3") ?

georgiboy
01-04-2009, 07:38 AM
I think your sendkeys are upsetting the rest of your code, as it works fine without them.

Private Sub CommandButton1_Click()
Dim SWs As SHDocVw.ShellWindows, vIE As SHDocVw.InternetExplorer
Set SWs = New SHDocVw.ShellWindows
For Each vIE In SWs
If Left(vIE.LocationURL, 4) = "http" Then
Range("a2").Value = vIE.LocationURL
End If
Next
Set SWs = Nothing
Set vIE = Nothing
Range("A2").Select
Application.OnKey "+^{Enter}"

'SendKeys "{enter}"
'SendKeys "{F5}A2{ENTER}{F2}"
Application.OnKey "{tab}", ""
Application.OnKey "+{tab}", ""
keyCode = 9


Range("A3").Select
End Sub

Hope this helps

omnibuster
01-04-2009, 09:05 AM
Thnxs georgiboy,but...
I try Send Keys (Enter) because need activate Range A3
I change File but nothing happens?
Cursor dont moove in the Range A3 ???

georgiboy
01-04-2009, 09:40 AM
Try this

omnibuster
01-04-2009, 10:13 AM
Thanks georgiboy.
Works good.

Artik
01-04-2009, 10:30 AM
I think that this code will be more efficient:Sub GetIEWindows() ' Requires reference to Microsoft Internet Controls
Dim SWs As SHDocVw.ShellWindows ', vIE As SHDocVw.InternetExplorer
Dim i As Integer

Set SWs = New SHDocVw.ShellWindows
For i = SWs.Count - 1 To 0 Step -1
If CStr(SWs(i).LocationURL) Like "http*" Then
Range("A2").Value = CStr(SWs(i).LocationURL)
Exit For
End If
Next i
' For Each vIE In SWs
' If Left(vIE.LocationURL, 4) = "http" Then
' Range("a2").Value = vIE.LocationURL
' End If
' Next
Set SWs = Nothing
' Set vIE = Nothing
' Range("A3").Activate
Range("A3").Select '????
End Sub
BTW. It is the difference between the activation of a cell that selected the cell.
Run this code:Sub ActivateCell()
Range("A1:A5").Select
Range("A3").Activate
End Sub

Sub SelectCell()
Range("A1:A5").Select
Range("A3").Select
End Sub
Artik

omnibuster
01-04-2009, 01:11 PM
Thanks Artik.
You code best for me.

Problem with mooving cursor Solved. Good.
But why I was truing use different "SendKeys"???
In this case : Range("A2").Value = CStr(SWs(i).LocationURL)
in Range A2.Value is text but I need in Range A2 HyperLink???

Artik
01-04-2009, 03:42 PM
in Range A2.Value is text but I need in Range A2 HyperLink???No problem :)
Sub GetIEWindows() ' Requires reference to Microsoft Internet Controls
Dim SWs As SHDocVw.ShellWindows
Dim i As Integer
Dim Adres As String

Set SWs = New SHDocVw.ShellWindows

For i = SWs.Count - 1 To 0 Step -1
Adres = CStr(SWs(i).LocationURL)

If Adres Like "http*" Then
Range("A2").Hyperlinks.Add _
Anchor:=Range("A2"), _
Address:=Adres, _
TextToDisplay:="Bla bla bla" 'or TextToDisplay:= Adres
Exit For
End If
Next i

Range("A3").Select

Set SWs = Nothing

End Sub
Artik

omnibuster
01-04-2009, 11:19 PM
Thanks Artik.
Very helps me.

Like says Danny Cloven: I,m too old for this Sh.. :)