请教VBA的internet explorerExplorer.Application

16661人阅读
网络笔记(17)
IE控制(1)
目的留个备份,方便我以后去MSDN上找用法。
InternetExplorer Object
42 out of 82 rated this helpful&
Controls an instance of Windows Internet Explorer through automation.
Members Table
The following table lists the members exposed by the&InternetExplorer&object.
Description
Fires before navigation occurs in the given&object&(on either a window or frameset element).
Fires before navigation occurs in the given&object&(on either a window element or a frameset element).
Fires when the enabled state of a command changes.
Fires when a document is completely loaded and initialized.
Fires when a navigation operation begins.
Fires when a navigation operation finishes, is halted, or fails.
Fires to indicate that a file download is about to occur. If a file download dialog box can be displayed, this event fires prior to the appearance of the dialog box.
Fires after a navigation to a link is completed on either a&&element or a&&element.
Fires after a navigation to a link is completed on a&window&element or a&frameSet&element.
Fires when an error occurs during navigation.
Creates a new process to handle the navigation.
Fires when a new window is to be created.
Fires when a new window is to be created.
Raised when a new window is to be created. Extends&&with additional information about the new window.
Fires when the&&property is changed.
Fires when the&&property is changed.
Fires before the Internet Explorer application quits.
Fires when the&&property is changed.
Fires when the&&property is changed.
Fires when the&&property is changed.
Fires when the&&property of the&object&is changed.
Fires when a print template is instantiated.
Fires when a print template is destroyed.
Fired when an event occurs that impacts privacy, or when a user navigates away from a URL that has impacted privacy.
Fires when the progress of a download operation is updated on the&object.
Fires when the&&method of the&object&changes the value of a property.
Fired when a cross-domain redirect request is blocked.
Fires to indicate the progress and status of Microsoft Phishing Filter analysis of the current webpage.
Fires when there is a change in encryption level.
Fires when the status bar text of the&object&has changed.
Fired when a third-party URL is blocked.
Fires when the title of a document in the&object&becomes available or changes.
Not implemented.
Not implemented.
Not implemented.
Not implemented.
Fires when the visibility state of a content window, such as the browser window or a tab, changes.
Description
Computes the full size of the browser window when given the specified width and height of the content area.
Executes a command and returns the status of the command execution using the&&interface.
Gets the value associated with a user-defined property name.
Navigates backward one item in the history list.
Navigates forward one item in the history list.
Navigates to the current home or start page.
Navigates to the current search page.
Navigates to a resource identified by a URL or to a file identified by a full path.
Navigates the browser to a location that might not be expressed as a URL, such as a pointer to an item identifier list (PIDL) for an entity in the Windows Shell namespace.
Associates a user-defined name/value pair with the&object.
Queries the&object&for the status of commands using the&IOleCommandTarget&interface.
Closes the&object.
Reloads the file that is currently displayed in the&object.
Reloads the file that is currently displayed with the specified refresh level.
Shows or hides a specified browser bar.
Cancels a pending navigation or download, and stops dynamic page elements, such as background sounds and animations.
Description
Sets or gets a value that indicates whether the address bar of the&object&is visible or hidden.
Gets the automation object for the application that is hosting the&.
Gets a value that indicates whether the&object&is engaged in a navigation or downloading operation.
Gets an object reference to a container.
Gets the automation object of the active document, if any.
Retrieves the fully qualified path of the Internet Explorer executable.
Sets or gets a value that indicates whether Internet Explorer is in full-screen mode or normal window mode.
Sets or gets the height of the&object.
Gets the handle of the Internet Explorer main window.
Sets or gets the coordinate of the left edge of the&object.
Retrieves the path or title of the resource that is currently displayed.
Gets the URL of the resource that is currently displayed.
Sets or gets a value that indicates whether the Internet Explorer menu bar is visible.
Retrieves the frame name or application name of the&object.
Sets or gets a value that indicates whether the&object&is operating in offline mode.
Gets the parent of the&object.
Retrieves the system folder of the Internet Explorer executable.
Gets the ready state of the&object.
Sets or gets a value that indicates whether the&object&is registered as a top-level browser window.
Sets or gets a value that indicates whether the&object&is registered as a drop target for navigation.
Sets or gets a value that indicates whether the&object&can be resized.
Sets or gets a value that indicates whether the&object&can display dialog boxes.
Sets or gets a value that indicates whether the status bar for the&object&is visible.
Sets or gets the text in the status bar for the&object.
Sets or gets whether the&object&is in theater mode.
Sets or gets whether toolbars for the&object&are visible.
Sets or gets the coordinate of the top edge of the&object.
Gets a value that indicates whether the&object&is a top-level container.
Gets the user type name of the contained document object.
Sets or gets a value that indicates whether the&object&is visible or hidden.
Sets or gets the width of the&object.
Internet Explorer&8. On Windows&Vista, to create an instance of Internet Explorer running at a medium integrity level, pass&CLSID_InternetExplorerMedium&(defined in exdisp.idl) to&.
The resulting&InternetExplorerMedium&object supports the same events, methods, and properties as the&InternetExplorer&object.
The following example uses&&in Microsoft Visual Basic to launch an instance of Internet Explorer.
Dim IE As SHDocVw.InternetExplorer
Set IE = CreateObject(&InternetExplorer.Application&)
The following C# example launches an instance of Internet Explorer and navigates to a Web page. The code also demonstrates how to create an event handler to listen for the&&event.
The project requires a reference to the Microsoft Internet Controls (SHDocVw) type library.
using System.Collections.G
using System.T
namespace ConsoleApplication1
class EventHandlers
public void OnBeforeNavigate2(object sender, ref object URL,
ref object Flags, ref object Target,
ref object PostData, ref object Headers,
ref bool Cancel)
Console.WriteLine(&BeforeNavigate2 fired!&);
class Program
static void Main(string[] args)
EventHandlers e = new EventHandlers();
SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
object Empty = 0;
object URL = &&;
// override BeforeNavigate2 event
IE.BeforeNavigate2 += new
SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(
e.OnBeforeNavigate2);
IE.Visible =
IE.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);
System.Threading.Thread.Sleep(5000);
IE.Quit();
Object&Information
CLSID_InternetExplorer
Minimum availability
Internet Explorer 4.0
Minimum operating systems
Windows&98, Windows CE&4.0
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:197185次
积分:2866
积分:2866
排名:第9022名
原创:78篇
转载:42篇
评论:28条
(1)(1)(2)(1)(1)(3)(5)(6)(11)(7)(8)(1)(2)(4)(6)(6)(1)(3)(1)(2)(1)(1)(7)(11)(5)(2)(1)(1)(2)(2)(1)(2)(3)(2)(1)(2)(2)(2)(1)VBA调用浏览器打开指定网页的几种方法
您现在的位置:&&>>&&>>&&>>&正文
VBA调用浏览器打开指定网页的几种方法
作者: 文章来源:本站原创 点击数: 更新时间: 8:30:29
&&& 下面的几段VBA代码都可以打开浏览器并打开指定的网页:
&&& 方法一:用API打开默认的浏览器
&&& Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long&&& Sub OpenWebPage1()&&&& ShellExecute 0&, vbNullString, "", vbNullString, vbNullString, vbNormalFocus&&& End Sub
&&& 方法二:用“FollowHyperlink”方法:
&&& Sub OpenWebPage2()&&&&& ActiveWorkbook.FollowHyperlink Address:="", NewWindow:=True&&& End Sub
&&& 注意网址中要包含“http://”。
&&& 方法三:用“InternetExplorer”对象
&&& Sub OpenWebPage3()&&& Dim IE As Object&&& Set IE = CreateObject("InternetExplorer.Application")&&&&&& IE.Visible = True&&&&&& IE.Navigate ("")&&& End Sub
&&& 方法四:用Shell语句
&&& 这个方法可以用指定的浏览器打开某个网页。例如调用IE打开网址“”
&&& Sub OpenWebPage4()&&& Dim url As String&&& url = ""&&& Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE " & url, vbNormalFocus&&& End Sub
&&& 说明:
&&& 1.将“C:\Program Files\Internet Explorer\IEXPLORE.EXE ”换成其他浏览器程序,则可用指定的浏览器打开网页。例如系统中已安装遨游浏览器(Maxthon),并安装在“C:\Maxthon2”文件夹中,将上述语句更改为“C:\Maxthon2\Maxthon.exe ”将用Maxthon打开指定的网页。
&&& 2.注意“C:\Program Files\Internet Explorer\IEXPLORE.EXE ”的结尾处有一空格。如果忽略此空格,Excel将出现错误提示“文件未找到”。
上一篇文章:
下一篇文章:
&其他网友还在看:
 网友评论:(评论内容只代表网友观点,与本站立场无关!)
::发表评论::
评论内容:
请遵守及中华人民共和国其他各项有关法律法规。
严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
评论需要审核通过后才可见,本站管理员有权保留或删除评论内容。
评论内容只代表网友个人观点,与本网站立场无关。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Excel技巧天地 E-mail:VBA 中怎样使用internetexplorer.application 建立独立会话_百度知道How to print a web page with VBA?
How to print a web page with VBA?
How to print a web page with VBA?
With VBA, I do something like the following:
Set obIe = CreateObject(&InternetExplorer.Application&)
obIe.navigate (URLaddress)
The page loads, and now I want to print the page.
I've tried:
obIe.print
printer.print
obIe.document.print
and some others.
Nothing I've tried works.
Does anyone know the
correct way to do this?
Thank you in advance.
You need to have JavaScript enabled so that you can use this ...
Re: How to print a web page with VBA?
I haven't tested this, but I think it should work:
obIe.ExecWB 6, 0
You should also make sure the page is fully loaded
before calling it:
Do Until obIe.ReadyState = 4
& With VBA, I do something like the following:
& Set obIe = CreateObject(&InternetExplorer.Application&)
& obIe.navigate (URLaddress)
& The page loads, and now I want to print the page.
& I've tried:
& obIe.print
& me.print
& printer.print
& obIe.document.print
& and some others.
Nothing I've tried works.
Does anyone know the
& correct way to do this?
& Thank you in advance.
You need to have JavaScript enabled so that you can use this ...
RE: How to print a web page with VBA?
here is a VBScript (tested) that print a Web page.
I think it will also work in VBA.
alt. Link:
&Dudely& wrote:
& With VBA, I do something like the following:
& Set obIe = CreateObject(&InternetExplorer.Application&)
& obIe.navigate (URLaddress)
& The page loads, and now I want to print the page.
& I've tried:
& obIe.print
& me.print
& printer.print
& obIe.document.print
& and some others.
Nothing I've tried works.
Does anyone know the
& correct way to do this?
& Thank you in advance.
You need to have JavaScript enabled so that you can use this ...
Re: How to print a web page with VBA?
& here is a VBScript (tested) that print a Web page.
& I think it will also work in VBA.
Your link seems to go around in circles, and it's basically
the same code I already posted.
The code, so people don't have to track it down:
On Error Resume Next
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Const PRINT_WAITFORCOMPLETION = 2
Dim oIExplorer : Set oIExplorer =
CreateObject(&InternetExplorer.Application&)
oIExplorer.Navigate &http://www.scriptbox.at.tt/&
oIExplorer.Visible = 1
Do while oIExplorer.ReadyState && 4
wscript.sleep 1000
oIExplorer.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
--------------
Or for anyone who wants to get the actual file, the
real download link is here:
20Web%20Page.vbs&filename=Open%20and%20print%20a%20Web%20Page.vbs
You need to have JavaScript enabled so that you can use this ...
Re: How to print a web page with VBA?
This doccumentation of ExecWB might be useful to people.
The parameter options are not easy to find.
ExecWB Method
object.ExecWB nCmdID, nCmdExecOpt, [pvaIn], [pvaOut]
object Required. An object expression that evaluates to an object in the
Applies To list.
nCmdID Required. A long integer that represents the identifier of the
command to execute.
nCmdExecOpt Required. A long integer that represents the options set for
executing the command.
pvaIn Optional. A variant used for specifying command input arguments.
pvaOut Optional. A variant used for specifying command output arguments
______________
first parameter - nCmdID options:
______________
OLECMDID_OPEN
OLECMDID_NEW
OLECMDID_SAVE
OLECMDID_SAVEAS
OLECMDID_SAVECOPYAS
OLECMDID_PRINT
OLECMDID_PRINTPREVIEW
OLECMDID_PAGESETUP
OLECMDID_SPELL
OLECMDID_PROPERTIES
OLECMDID_CUT
OLECMDID_COPY
OLECMDID_PASTE
OLECMDID_PASTESPECIAL
OLECMDID_UNDO
OLECMDID_REDO
OLECMDID_SELECTALL
OLECMDID_CLEARSELECTION
OLECMDID_ZOOM
OLECMDID_GETZOOMRANGE
OLECMDID_UPDATECOMMANDS
OLECMDID_REFRESH
OLECMDID_STOP
OLECMDID_HIDETOOLBARS
OLECMDID_SETPROGRESSMAX
OLECMDID_SETPROGRESSPOS
OLECMDID_SETPROGRESSTEXT
OLECMDID_SETTITLE
OLECMDID_SETDOWNLOADSTATE
OLECMDID_STOPDOWNLOAD
} OLECMDID;
OLECMDID_OPEN
File menu, Open command
OLECMDID_NEW
File menu, New command
OLECMDID_SAVE
File menu, Save command
OLECMDID_SAVEAS
File menu, Save As command
OLECMDID_SAVECOPYAS
File menu, Save Copy As command
OLECMDID_PRINT
File menu, Print command
OLECMDID_PRINTPREVIEW
File menu, Print Preview command
OLECMDID_PAGESETUP
File menu, Page Setup command
OLECMDID_SPELL
Tools menu, Spelling command
OLECMDID_PROPERTIES
File menu, Properties command
OLECMDID_CUT
Edit menu, Cut command
OLECMDID_COPY
Edit menu, Copy command
OLECMDID_PASTE
Edit menu, Paste command
OLECMDID_PASTESPECIAL
Edit menu, Paste Special command
OLECMDID_UNDO
Edit menu, Undo command
OLECMDID_REDO
Edit menu, Redo command
OLECMDID_SELECTALL
Edit menu, Select All command
OLECMDID_CLEARSELECTION
Edit menu, Clear command
OLECMDID_ZOOM
View menu, Zoom command (see below for details)
OLECMDID_GETZOOMRANGE
Retrieves zoom range applicable to View Zoom. (See below for details.)
OLECMDID_UPDATECOMMANDS
Informs the receiver, usually a frame, of state changes. The receiver can
then query the status of the commands whenever convenient.
OLECMDID_REFRESH
Asks the receiver to refresh its display. Implemented by the
document/object.
OLECMDID_STOP
Stops all current processing. Implemented by the document/object.
OLECMDID_HIDETOOLBARS
View Menu, Toolbars command. Implemented by the document/object to hide its
OLECMDID_SETPROGRESSMAX
Sets the maximum value of a progress indicator if one is owned by the
receiving object, usually a frame. The minimum value is always zero.
OLECMDID_SETPROGRESSPOS
Sets the current value of a progress indicator if one is owned by the
receiving object, usually a frame.
OLECMDID_SETPROGRESSTEXT
Sets the text contained in a progress indicator if one is owned by the
receiving object, usually a frame. If the receiver currently has no progress
indicator, this text should be displayed in the status bar (if one exists)
as with IOleInPlaceFrame::SetStatusText.
OLECMDID_SETTITLE
Sets the title bar text of the receiving object, usually a frame.
OLECMDID_SETDOWNLOADSTATE
Called by the object when downloading state changes. Takes a VT_BOOL
parameter, which is TRUE if the object is downloading data and FALSE if it
not. Primarily implemented by the frame.
OLECMDID_STOPDOWNLOAD
Stops the download when executed. Typically, this command is propagated to
all contained objects. When queried, sets MSOCMDF_ENABLED. Implemented by
the document/object.
____________________
second parameter -
nCmdExecOpt options:
____________________
OLECMDEXECOPT_DODEFAULT
OLECMDEXECOPT_PROMPTUSER
LECMDEXECOPT_DONTPROMPTUSER
OLECMDEXECOPT_SHOWHELP
OLECMDEXECOPT_DODEFAULT
Prompt the user for input or not, whichever is the default behavior.
OLECMDEXECOPT_PROMPTUSER
Execute the command after obtaining user input.
OLECMDEXECOPT_DONTPROMPTUSER
Execute the command without prompting the user. For example, clicking the
Print toolbar button causes a document to be immediately printed without
user input.
OLECMDEXECOPT_SHOWHELP
Show help for the corresponding command, but do not execute
You need to have JavaScript enabled so that you can use this ...
Re: How to print a web page with VBA?
Is that really the VBA way to do it?
I've never heard of
ExecWB (which means nothing, but) how does one know where to find or
look for something like that in the first place?
Thank you very very much!
I'll give it a try.
On Oct 10, 7:19*am, &mayayana& &mayaXXy...@xxxxxx& wrote:
& This doccumentation of ExecWB might be useful to people.
& The parameter options are not easy to find.
& ExecWB Method
& object.ExecWB nCmdID, nCmdExecOpt, [pvaIn], [pvaOut]
& object Required. An object expression that evaluates to an object in the
& Applies To list.
& nCmdID Required. A long integer that represents the identifier of the
& command to execute.
& nCmdExecOpt Required. A long integer that represents the options set for
& executing the command.
& pvaIn Optional. A variant used for specifying command input arguments.
& pvaOut Optional. A variant used for specifying command output arguments
& ______________
& first parameter - nCmdID options:
& ______________
& * * *OLECMDID_OPEN * * * * * * *= 1,
& * * *OLECMDID_NEW * * * * * * * = 2,
& * * *OLECMDID_SAVE * * * * * * *= 3,
& * * *OLECMDID_SAVEAS * * * * * *= 4,
& * * *OLECMDID_SAVECOPYAS * * * *= 5,
& * * *OLECMDID_PRINT * * * * * * = 6,
& * * *OLECMDID_PRINTPREVIEW * * *= 7,
& * * *OLECMDID_PAGESETUP * * * * = 8,
& * * *OLECMDID_SPELL * * * * * * = 9,
& * * *OLECMDID_PROPERTIES * * * *= 10,
& * * *OLECMDID_CUT * * * * * * * = 11,
& * * *OLECMDID_COPY * * * * * * *= 12,
& * * *OLECMDID_PASTE * * * * * * = 13,
& * * *OLECMDID_PASTESPECIAL * * *= 14,
& * * *OLECMDID_UNDO * * * * * * *= 15,
& * * *OLECMDID_REDO * * * * * * *= 16,
& * * *OLECMDID_SELECTALL * * * * = 17,
& * * *OLECMDID_CLEARSELECTION * *= 18,
& * * *OLECMDID_ZOOM * * * * * * *= 19,
& * * *OLECMDID_GETZOOMRANGE * * *= 20
& * * *OLECMDID_UPDATECOMMANDS * *= 21
& * * *OLECMDID_REFRESH * * * * * = 22
& * * *OLECMDID_STOP * * * * * * *= 23
& * * *OLECMDID_HIDETOOLBARS * * *= 24
& * * *OLECMDID_SETPROGRESSMAX * *= 25
& * * *OLECMDID_SETPROGRESSPOS * *= 26
& * * *OLECMDID_SETPROGRESSTEXT * = 27
& * * *OLECMDID_SETTITLE * * * * *= 28
& * * *OLECMDID_SETDOWNLOADSTATE *= 29
& * * *OLECMDID_STOPDOWNLOAD * * *= 30
& } OLECMDID;
& Elements
& OLECMDID_OPEN
& File menu, Open command
& OLECMDID_NEW
& File menu, New command
& OLECMDID_SAVE
& File menu, Save command
& OLECMDID_SAVEAS
& File menu, Save As command
& OLECMDID_SAVECOPYAS
& File menu, Save Copy As command
& OLECMDID_PRINT
& File menu, Print command
& OLECMDID_PRINTPREVIEW
& File menu, Print Preview command
& OLECMDID_PAGESETUP
& File menu, Page Setup command
& OLECMDID_SPELL
& Tools menu, Spelling command
& OLECMDID_PROPERTIES
& File menu, Properties command
& OLECMDID_CUT
& Edit menu, Cut command
& OLECMDID_COPY
& Edit menu, Copy command
& OLECMDID_PASTE
& Edit menu, Paste command
& OLECMDID_PASTESPECIAL
& Edit menu, Paste Special command
& OLECMDID_UNDO
& Edit menu, Undo command
& OLECMDID_REDO
& Edit menu, Redo command
& OLECMDID_SELECTALL
& Edit menu, Select All command
& OLECMDID_CLEARSELECTION
& Edit menu, Clear command
& OLECMDID_ZOOM
& View menu, Zoom command (see below for details)
& OLECMDID_GETZOOMRANGE
& Retrieves zoom range applicable to View Zoom. (See below for details.)
& OLECMDID_UPDATECOMMANDS
& Informs the receiver, usually a frame, of state changes. The receiver can
& then query the status of the commands whenever convenient.
& OLECMDID_REFRESH
& Asks the receiver to refresh its display. Implemented by the
& document/object.
& OLECMDID_STOP
& Stops all current processing. Implemented by the document/object.
& OLECMDID_HIDETOOLBARS
& View Menu, Toolbars command. Implemented by the document/object to hide its
& toolbars.
& OLECMDID_SETPROGRESSMAX
& Sets the maximum value of a progress indicator if one is owned by the
& receiving object, usually a frame. The minimum value is always zero.
& OLECMDID_SETPROGRESSPOS
& Sets the current value of a progress indicator if one is owned by the
& receiving object, usually a frame.
& OLECMDID_SETPROGRESSTEXT
& Sets the text contained in a progress indicator if one is owned by the
& receiving object, usually a frame. If the receiver currently has no progress
& indicator, this text should be displayed in the status bar (if one exists)
& as with IOleInPlaceFrame::SetStatusText.
& OLECMDID_SETTITLE
& Sets the title bar text of the receiving object, usually a frame.
& OLECMDID_SETDOWNLOADSTATE
& Called by the object when downloading state changes. Takes a VT_BOOL
& parameter, which is TRUE if the object is downloading data and FALSE if it
& not. Primarily implemented by the frame.
& OLECMDID_STOPDOWNLOAD
& Stops the download when executed. Typically, this command is propagated to
& all contained objects. When queried, sets MSOCMDF_ENABLED. Implemented by
& the document/object.
& ____________________
& second parameter - *nCmdExecOpt options:
& ____________________
& * * OLECMDEXECOPT_DODEFAULT * * * *= 0,
& * * OLECMDEXECOPT_PROMPTUSER * * * = 1,
& * * LECMDEXECOPT_DONTPROMPTUSER * *= 2,
& * * OLECMDEXECOPT_SHOWHELP * * * * = 3
& OLECMDEXECOPT_DODEFAULT
& Prompt the user for input or not, whichever is the default behavior.
& OLECMDEXECOPT_PROMPTUSER
& Execute the command after obtaining user input.
& OLECMDEXECOPT_DONTPROMPTUSER
& Execute the command without prompting the user. For example, clicking the
& Print toolbar button causes a document to be immediately printed without
& user input.
& OLECMDEXECOPT_SHOWHELP
& Show help for the corresponding command, but do not execute
You need to have JavaScript enabled so that you can use this ...
Re: How to print a web page with VBA?
On Oct 9, 9:55*pm, &mayayana& &mayaXXy...@xxxxxx& wrote:
& I haven't tested this, but I think it should work:
& obIe.ExecWB 6, 0
& * *You should also make sure the page is fully loaded
& before calling it:
& *Do Until obIe.ReadyState = 4
& & With VBA, I do something like the following:
& & Set obIe = CreateObject(&InternetExplorer.Application&)
& & obIe.navigate (URLaddress)
& & The page loads, and now I want to print the page.
& & I've tried:
& & obIe.print
& & me.print
& & printer.print
& & obIe.document.print
& & and some others. *Nothing I've tried works. *Does anyone know the
& & correct way to do this?
& & Thank you in advance.- Hide quoted text -
& - Show quoted text -
For whatever reason the loop code doesn't seem to work, instead I use
a sleep 5000.
It may have to do with the fact that I'm using the
Click and Onclick methods (when I posted, I simplified so as not to
confuse the real issue of needing to print), I really don't know and
don't care about that at the moment, I do know the page is fully
loaded, because I'm stepping through it and I don't move on until the
page is done.
The real issue:
Your code works!
Well, partially.
It prints the
first page, but not the second.
There are only 2 pages.
The second
page is all images.
For my purposes it's not absolutely critical that
I get the second page, however it would be nice.
Any ideas why it
stops after the first page?
In fact, I now notice that on the printed
page it says &Page 1 of 1&, so it doesn't even recognize that there's
more than one page.
Or perhaps 1 very long page?
Thank you again
You need to have JavaScript enabled so that you can use this ...
Re: How to print a web page with VBA?
Is that really the VBA way to do it?
I've never heard of
ExecWB (which means nothing, but) how does one know where to find or
look for something like that in the first place?
ExecWB is a method of both IE and the WebBrowser
control used in VB (which is also really just IE without
the window frame &chrome&).
It's not so easy to find out this stuff. That's why I
posted the detailed documentation. IE has a fairly extensive
object model. And the IE DOM for webpage scripting is
far bigger. So it's hard to research it without having a
local copy of the MSDN documentation. (The online
MSDN system is a mess, full of dead links and bloat.
When looking for one particular item I always start with
Google. When you need to find a lot of info., like
documentation of all IE object properties and methods,
the spread out disarray of MSDN online makes that
virtually impossible.)
You need to have JavaScript enabled so that you can use this ...
Re: How to print a web page with VBA?
For whatever reason the loop code doesn't seem to work, instead I use
a sleep 5000.
It should work if it's called after Navigate.
I usually use it with WScript.Sleep 100 in
the loop, but it should work either way.
The real issue:
Your code works!
Well, partially.
It prints the
first page, but not the second.
There are only 2 pages.
The second
page is all images.
The second page? There's only one page that
one navigates to. If there's a page 2, as with many
news articles that run multiple pages, that's just
a link on the first page. You'd have to navigate to
that separately and load it as a second document.
You need to have JavaScript enabled so that you can use this ...
How to print a web page with VBA?
Site Links
Old server
Windows Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows 10" and related materials are trademarks of Microsoft Corp.
All times are GMT -5. The time now is .

我要回帖

更多关于 internet explorer 11 的文章

 

随机推荐