![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Posts: 2
|
Can someone tell me how to open an Internet Explorer page, select the entire page (ctrl a)copy it to the clip board (ctrl c) and return to EXCEL and paste (ctrl v) onto a worksheet. This, of course, all must be done from a signle click on an existing link in EXCEL.
|
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Do you mean you want a VBA macro to do all of this for you?
To literally do what you just described you're going to have to use "SendKeys" and "AppActivate". That's assuming you can hardcode the IE title bar text. |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Mark, I too had the same idea to use sendkeys, but can't get it to work.
ActiveWorkbook.FollowHyperlink Address:="http://sports.yahoo.com/" AppActivate "Microsoft Internet Explorer" SendKeys "^A" SendKeys "^C" AppActivate "Microsoft Excel" ActiveSheet.Paste Any ideas... |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
You have to have the exact title in IE for this to work. Personally I would probably look into using API calls to get the handle of the IE window, but I don't have that code in work. Anyway, for AppActivate and Sendkeys to work you need to put pauses to let the computer catch up.
this code works for me:
_________________ [b] Mark O'Brien [ This Message was edited by: Mark O'Brien on 2002-03-22 15:07 ] |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
I got that to work too, but it still doesn't solve the problem of going to a different website. I'm still working on the API call part (I am trying to do it with the class name, not the title). Do you know what the class name is for Internet Explorer?
[ This Message was edited by: Al Chara on 2002-03-22 16:33 ] |
|
|
|
|
|
#6 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
How have you called the routine..... Have you Shelled out to it.....?? Ivan |
|
|
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Hey guys,
Try the following code: Option Explicit Public Const SW_RESTORE As Long = 9& Public Const GW_CHILD As Long = 5& Public Const GW_HWNDNEXT As Long = 2& Declare Function GetDesktopWindow& Lib "user32" () Declare Function GetWindow& Lib "user32" (ByVal hWnd&, ByVal wCmd&) Public Declare Function GetWindowText& Lib "user32" Alias "GetWindowTextA" _ (ByVal hWnd&, ByVal lpString$, ByVal cch&) Declare Function ShowWindow& Lib "user32" (ByVal hWnd&, ByVal nCmdShow&) Public Declare Function SetForegroundWindow& Lib "user32" (ByVal hWnd&) Sub Main() Const BaseCaption As String = "Internet Explorer" Dim AppWindow&, sTemp$, StartTime, CycleTime StartTime = Now AppWindow = GetWindow(GetDesktopWindow(), GW_CHILD) Do While CycleTime - StartTime < TimeValue("00:00:01") sTemp = String$(180, False) Call GetWindowText(AppWindow, sTemp, 179) If InStr(sTemp, BaseCaption) Then ActivateWindow AppWindow Exit Sub End If AppWindow = GetWindow(AppWindow, GW_HWNDNEXT) CycleTime = Now Loop MsgBox "The window is not open" End Sub Private Sub ActivateWindow(ByVal AppWindow&) Call ShowWindow(AppWindow, SW_RESTORE) Call SetForegroundWindow(AppWindow) End Sub It searches for the string "Internet Explorer" in the title of all open windows. If one of the titles is a match it activates that window, if there are now matches then it returns a message saying there were no matches. (Got some of the code floating on the internet) _________________ Hope this helps. Kind regards, Al. [ This Message was edited by: Al Chara on 2002-03-22 18:28 ] |
|
|
|
|
|
#8 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Al....Great...thanks
Ivan |
|
|
|
|
|
#9 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Al
I Changed Public const to include Public Const SW_MAXIMIZE As Long = 3& Plus I changed call to MAX window; Call ShowWindow(AppWindow, SW_MAXIMIZE) As I want the window Maximized. Ivan [ This Message was edited by: Ivan F Moala on 2002-03-23 03:22 ] |
|
|
|
|
|
#10 |
|
New Member
Join Date: Mar 2002
Posts: 2
|
Hey! Thanks for all the replies to my question! I'll let you know how it works!
Well, After working out some of the details that AppActivate and SendKeys works great! Thanks to Al & Brain! Here's another problem for you. How can I send a URL string to the address window after navigating to a web page from an Excel Hyperlink? [ This Message was edited by: ctcoach141 on 2002-03-26 06:08 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|