All,
I am trying to use MS Word to print the current web page.
I have a print button that call an agent and run on the server.
The problem is that it make MS Word visible on the server console and not on the user machine.
If I run my agent locally, it will make MS Word visible on the user (or my machine).
I know this is all working like it should but I am wondering if there is a way to make MS Word visible when called from a button on the web calling an agent.
this is some of the code I am talking about:
Dim objWord As Variant
Dim docWord As Variant
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
Dim object As NotesEmbeddedObject
Dim rtitem As Variant
Set docWord = objWord.Documents.Open("L:\Lotus\Domino\data\domino\html\Attachments\cal\templates\gage-grid111.docx")
Basically no. All LotusScript on the web runs on the Domino server and can't do anything with client software, and there's nothing you can do about that as far as I know.
Some alternatives might be possible depending on the requirements of your application.
Firstly, does the thing you're printing have to be a Word document? If the same content can be generated with HTML and CSS, then you could open that as a normal web page and print it using client-side javascript.
If it really must be a Word document, then one of the following options might suit you:
Store the Word document in a Notes document accessible to the web user, or in some other server-side location accessible by a URL, then show the web user a link to the Word document so they can download and print it; or...
I've never tried this, but it might be possible to control Word on the client machine using ActiveXObject in javascript, or there may be some other Windows-only javascript feature to do this. If this is possible, browser support is likely to be limited, and subject to security restrictions.
What exactly do you mean by "use Word to print the current page"? If it's the exact contents of the screen, why use Word when a browser can print the page? How is your web page created, using a Notes form or XPages?
Probably the best you can do is use CSS directives for when the document is printed. Either make a 2nd form that displays the data exactly as you want them printed, or put a hidden div in the same form (e.g. at the bottom) that contains the info to be printed. Use CSS in such a way that the original info isn't printed, only the normally hidden div.
You could print to a PDF file, I don't know if/how printing to Word works.
Related
We have been using PDF file as a part of help docs in our vb.net desktop application. In PDF, we would traverse to the certain chapter in the PDF doc.
Now we have decided to use MadCap Flare as documentation tool. We have a menu item in vb.net form for documentation. On click of the link, we want to open the specific chapter of the Flare documentation.
You know managing content with single-source XML authoring is possible when using MapCad Flare (I'm not using Flare!). You can publish content to an increasing number of formats including HTML5, WebHelp, PDF, Word, XHTML, Clean XHTML, EPUB, DITA and more by MapCad Flare.
So, you may continue using PDF and the way connecting your vb.net desktop application help.
Using HTML based topics maybe another solution for your needs by creating Help for a form, a dialog or control with HTML files (See also: Help for controls with VB .NET).
Properties to display help (HTML file - local)
Activate the hlpProvider component hlpHtmlLocal and set the HelpNameSpace property of hlpHtmlLocal to the file name you want to work with.
We open a local HTML file with the dialog using the little button to the right.
The next step is to set the HelpNavigator property of a control (e.g. button) to a value of the HelpNavigator enumeration (see table below). Here we use Topic.
When the application is running click the HelpButton to enable "What's this .." Help. The cursor changes. Now click the button or press F1 when the button has focus. This will open the single HTML file in your browser.
It seems you can't use anchor names to jump to a specific part of your HTML file.
Properties to display help (HTML file - Server http://..)
Activate the hlpProvider component and set the HelpNameSpace property of hlpHtmlServer to the file name you want to work with. Here we use a http:// address of a single HTML file. If you provide the file on your company server, you don't have to update the help file with the customer.
The next step is to set the HelpNavigator property of a control (e.g. button) to a value of the HelpNavigator enumaration (see table below). Here we use Topic. Then we set the HelpKeyword on hlpHtmlSever property to e.g. "anchor3". Don't add a leading "#". Leave it empty if you want to open a HTML file without anchors. The Help Handles cmdControl2.Click Dim sHelpFile As String Dim sStartupPath As String '--- Initialize context-sensitive help --- Keyword property provides the key information to retrieve the help associated with the control.
When the application is running click the HelpButton to enable "What's this .." Help. The cursor changes. Now click the button or press F1 when the button has focus. This will open the single HTML file over the Internet in your browser.
I'm currently using Word documents as templates where blanks have to be filled dynamically/programmatically in PwoerBuilder.
This has always worked fine until the company moves on Windows 7.
In short, the Word application is opened and made invisible.
Word.Application.Visible = false
Except that sometimes, and I don't know why, once the template is accessed, Word opens itself just as if I had double-clicked the template byself through the Explorer - but I didn't.
So, it asks whether I want to open it in read-only mode, since the application already has a handle on the file. And even if I click [Cancel] not to open the file, Word opens with no document, then the application crashes.
It reports PowerBuilder System Error 35.
Error Number 35.
Error text = Error calling external object function open at line 24 in function of_fusion of object n_cst_9999.
The external object that the application is trying to call a function against is Word.
oleobject lole_word
lole_word = create oleobject
lole_word = ConnectToNewObject("Word.Application")
lole_word.Documents.Open("templatefile.docx")
It may work for a few documents, and after a few, the problem comes up. This is the first time ever I meet with this issue.
I'll be glad to answer anyone's question who's trying to help.
Will, you may try setting DisplayAlerts and FeatureInstall properties on Word Application object.
That hid most of word alerts for us. (The code is from C# project and may not be exactly what you need)
Word.Application.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
Word.Application.FeatureInstall = 0;
You may also try making a copy of the file before opening it to avoid accessing same .docx from different threads - if that may be the case.
I am working on creating multiple documents from source document.
I am using:
objWordApp.Documents.Open("D:\Template\Aptletter.doc")
I modify the above document and save in another folder.
While creating documents, word files are opening and closing multiple times. So user unable to do another work on the same PC.
How to stop open file or Is there any method to modify document without above method?
So please suggest
Thanks in Advance
DEV
The visibility of a word document being controlled via interop can be set using the WordApplication.Visible attribute.
This attribute is, as you can see, at the Application level. If you've already opened a document using that WordApplication, you can't suddenly make the application invisible using the attribute.
What you can do, though, is create another instance of WordApplication. Call it InvisibleWordApplication for clarity, and set InvisibleWordApplication.Visible = false right from the start. Then open your document using that application, and you should be set.
I have a tried reading an embedded excel document in a word document. I followed the code specified at this blog article:
http://vbadud.blogspot.com/2010/08/how-to-read-excel-sheet-embedded-in.html
Dim oWB As Excel.Workbook
Dim oIShape As InlineShape
For Each oIShape In ActiveDocument.InlineShapes
If InStr(1, oIShape.OLEFormat.ProgID, "Excel") Then
oIShape.OLEFormat.Activate
Set oWB = oIShape.OLEFormat.Object
oWB.Sheets(1).Range("A1").Value = "ProdID"
End If
Next oIShape
It works fine but the Activate line causes the document to flicker on each excel document I read. I tried to remove the oIShape.OLEFormat.Activate code but it causes the next line to throw a "Runtime error '430' (class does not support Automation or does not support expect).
The question is there any other way to access embedded excel without calling the Activate method?
This is tricky! The short answer is, no. Not with an embedded Excel.
I did some experimentation and some research. Since I could not find any sources that specifically explained the behavior. this is somewhat a guess on my part. It appears that when you embed the Excel spreadsheet into your word document essentially Word stores a link of spreadsheet, which displays only the appearance because it needs to be interpreted with the Excel program. Until you actually active the shape, you cannot interact with it because that cannot be done with Word directly. This article alludes to the behavior, but doesn't explain it. Here's a quote:
If you edit the object in Word, click anywhere outside the object to return
to the destination file.
If you edit the object in the source program in a separate window,
click Exit on the File menu of the source program to return to the
destination file.
You may have noticed that even if you use. Application.ScreenUpdating = false it still does the flickering you mention. This is because you are using a different application when you access the shapes! Every time you active the shape, the object specific menus etc load.
A possible work around:
If instead of embedding Excel Spreadsheets via the insert menu, you can instead add a control. On my machine using Office 2003 the comparible one is: Microsoft Office Spreadsheet 11.0 This is technically a web control, but the methods and behavior are very comparable to an Excel workbook.
Using the control instead of the handy inserted object, with a slight variation of your code I was able to comment out your activate command and the code ran as expected. Specifically, I had to change these lines:
Dim oWB As Spreadsheet instead of Excel.Workbook.
If InStr(1, oIShape.OLEFormat.ProgID, "OWC11.Spreadsheet.11") Then instead of "Excel"
Basically you can decide... Activate your embedded object that requires Excel to interpret, or use a different control that doesn't require activation.
I'm big into developing with VBA (cuts through corporate red tape with a chainsaw) and have become adroit at extending these macros with various add-in references (IE, Excel, Outlook, and Word automation objects, IE of which is my best 'trick').
Anyway, I'm curious how I could get a list of the OOP 'guts' of a given object on a web page, seeing as my IDE cannot give any hints.
Here's some sample code, make sure shdocvw.dll is referenced, and presume 'www.mywebsite.com' has a username and password text box as well as a button to log in:
Sub MyIEAutomationExample
Dim IE as InternetExplorer
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate ("http://www.mywebsite.com")
Do Until IE.ReadyState = READYSTATE_COMPLETE 'Delay for loading page
Loop
IE.Document.all.Item("tbxUserName").Value = "Nxwtypx"
IE.Document.all.Item("tbxPassword").Value = InputBox("Please enter your password.")
IE.Document.all.Item("btnLogin").Click
End Sub
The question on my mind, is what if I wanted to ascertain the other Properties/Methods/Events of tbxUserName, tbxPassword, or btnLogin? Is there some kind of reference availiable for standard objects?
And even then, what about kinkier objects like Rich Text Boxes, for all I know, that were developed in-house?
If it's a standard HTML page you are looking at then the document property of the InternetExplorer object should return an HTMLDocument object. If you add a reference to "Microsoft HTML Object Library" then you can see the object model for HTMLDocument.
Details for individual HTML elements can be found under "HTML" + the element name + "Element". For example, details for button elements are found under HTMLButtonElement
I'm not sure what you can find out about non-standard objects. Remou's suggestion of adding a watch may be the best idea here. You can then use the Watch window to locate the node which corresponds to the non-standard object and see which (if any) properties it exposes.
Finally, if the document you are looking at is in XHTML or XML format then you may want to use XMLHttpRequest (instead of InternetExplorer) as this lets you use a more powerful lanaguage called XPath to locate the nodes you want to examine - see this answer to a different question for details
There is little I can think of immediately to add to the answer already given except, I often use the TypeName function e.g.
typename(myVariableOfInterest)
Typename
Returns a String that provides information about a variable.
For example, when working with a webpage I might write:
Dim a As Object: Set a = .document.getElementById("elementID")
And then in the immediate window do
TypeName(a)
Which generally tells me the datatype I am working with, for example, HTMLTable.
I take the returned string and then either, in no particular order:
Google to find the listed methods/properties
MSDN Developer search to find the listed methods/properties
Use the object browser in Excel to search for the string and the listed methods/properties