|
-
Jan 7th, 2006, 02:56 PM
#1
Thread Starter
New Member
close window
I dont know much about Visual Basic, but here is what I have:
Sub Macro1()
For x = 1 To 10
ActiveDocument.FollowHyperlink Address:="http://www.spftservers.com", _
NewWindow:=False, AddHistory:=True
Next x
End
End Sub
That basicallly opens up an internet explorer window during the loop. What I want it to do is close that internet explorer window after it is opened. Also, I would preferably like it to wait 2 seconds before closing the window. I need the code for the program since I dont know much. Thank you.
Here is what my total program is to do, so if you can write better code...:
1. Open a new Mozilla/Internet Window
2. Go to a certain website
3. **Optional** Wait 5 seconds
3. Close that Window
4. Have a loop with a certain amount runs
Thanks
-
Jan 7th, 2006, 03:09 PM
#2
Re: close window
Welcome to the Forums. 
Are you doing this in Word's VBA?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 7th, 2006, 06:52 PM
#3
Thread Starter
New Member
-
Jan 7th, 2006, 07:06 PM
#4
Re: close window
Why do you need it to open to the same url many times?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 7th, 2006, 07:24 PM
#5
Thread Starter
New Member
Re: close window
im running a test for my network, and then my office.
-
Jan 7th, 2006, 07:32 PM
#6
Re: close window
Looks like your going to have to use some APIs to FindWindow of the correct browser instance and then PostMessage to close it. You can download the API declarations from allapi.net for the API Viewer utility.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 7th, 2006, 07:38 PM
#7
Thread Starter
New Member
Re: close window
how do i do those? sorry im a beginner at this
-
Jan 7th, 2006, 07:47 PM
#8
Thread Starter
New Member
Re: close window
ok i got both of these could someone please help me put it together
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function CloseWindow Lib "user32.dll" ( _
ByVal hwnd As Long) As Long
-
Jan 7th, 2006, 08:29 PM
#9
Re: close window
The class name for IE is "IEFrame" so it depends on the browser your looking to close. Is it IE or FF or ??
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 7th, 2006, 08:35 PM
#10
Thread Starter
New Member
Re: close window
OK i have this:
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Declare Function CloseWindow Lib "user32.dll" ( _
ByVal hWnd As Long) As Long
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 1/4/2006 by yes
'
For y = 1 To 10
For x = 1 To 1000
ActiveDocument.FollowHyperlink Address:="http://www.spftservers.com", _
NewWindow:=True, AddHistory:=True
Dim lIEFramehWnd As Long
lIEFramehWnd = FindWindow("IEFrame", vbNullString)
Next x
Next y
End
This should find the IE window, now how do i close it?
-
Jan 7th, 2006, 08:44 PM
#11
Re: close window
You dont need the FindWindowEx as its only for child windows.
VB Code:
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function CloseWindow Lib "user32.dll" ( _
ByVal hWnd As Long) As Long
Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 1/4/2006 by yes
'
Dim lIEFramehWnd As Long
For y = 1 To 10
For x = 1 To 1000
ActiveDocument.FollowHyperlink Address:="http://www.spftservers.com", _
NewWindow:=True, AddHistory:=True
'Make a pause
Sleep 5000
lIEFramehWnd = FindWindow("IEFrame", vbNullString)
If lIEFramehWnd <> 0 Then
CloseWindow lIEFramehWnd
Else
MsgBox "Cant Find IE"
End If
Next
Next
End
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 7th, 2006, 09:01 PM
#12
Thread Starter
New Member
Re: close window
ok its working, but except for closing them, its just minimizing them
-
Jan 7th, 2006, 09:11 PM
#13
Re: close window
I was unsure about that API but the PostMessage that I originally suggested will work.
VB Code:
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_QUIT As Long = &H12
Private Const WM_CLOSE As Long = &H10
'Example usage
PostMessage lIEFramehWnd, WM_QUIT, 0&, 0&
'Or
PostMessage lIEFramehWnd, WM_CLOSE, 0&, 0&
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|