Is there a way (in VB.net/VBA) to search for a string in a .doc file without physically opening it?
The question may sound silly but I have code that searches 100's of documents at a time while opening them all up one-by-one (using For Each, FileSystemObjectand oWord.Document.Open(Filename.doc) and it takes ages.
I noticed that when you search for a document using the search box in Windows Explorer, the results are returned having found your search term in the TITLE of the document as well as the the CONTENTS of the document within the search window. The results where the search term was found INSIDE the document appears as a sort of text preview of all the text inside that document.I could be wrong but I read somewhere that all word documents contain some sort of xml file embedded within that contains (among other things) the text from the document itself.
So my question is, if Windows Explorer can do it without having to open a word process, can the same be done in code (VBA or VB.NET)to find a particular word inside a document?
Hope that makes sense,
Thanks.
Related
I have a word document with around a hundred bookmarks, each with a Macro programmed in for each Bookmark.
I created a word macro for each bookmark:
Sub Coronado()
Application.ActiveDocument.Bookmarks("Coronado").Select
End Sub
And then created a bat file to take me to the bookmark I need to go to:
"C:\Program Files (x86)\Microsoft Office\Office12\winword.exe" ""C:\Users\1241\Desktop\WorkFiles\HotelDel.docm"" /mCoronado
My new question is:
Is there a way to run this bat file, so that if the document is already open, it will just run the macro without reopening the document again.
I have several of these macros and bat files I am using, and would like the bat files to go to the macros in the word document without reopening the word document each time. After a while I would have numerous instances of the word document open, and then have to close them all.
OK, I have decided to go with VB Scripts, It has been a much easier process.
What I am doing is using a programmed voice software to activate scripts.
While I am talking to the customer, I say the name of the Word document, and then my voice command brings up the word document. As the customer asks questions, then I say the name of the question, and the voice command I have programmed in uses a VB Script to automatically go to that bookmark where the information I am trying to find for the customer is. This way I cut down on a lot of time searching through this word document fort the information the customer is looking for. This is all done with voice activated commands, such as "Parking Policy" or "Pet Policy". When I say these words, the computer automatically takes me to that bookmark in the document with no typing involved.
The issue I am having now, Is how to program a global Variable for each document I bring up. I need all previous variables cleared, and then I need the new variable put in place. For instance I say the name "Hotel Del Coronado" and that information document is brought forward on the screen. I need the path of that document to become the new variable for Hotel. Now when I say the name of the bookmark, it uses the path of the current document to go to that bookmark in the current document. This way I only have to program the Bookmark Scripts once. Each of my documents have the same bookmarks. So if I have the Variable Hotel set for the new document, Then all of the bookmark commands will be set for the new document.
I have been tasked with updating a spreadsheet that produces a report by replacing text in a template. Previously, the worksheet referenced an outside/separate file-- my job is to get it working in an embedded document.
I currently have text form fields for every input I want to insert within the embedded document template. As it stands, users can edit the document template however they like, but if they accidentally erase a text form field (again, where text is replaced via the vba macro) then it will break the macro and the spreadsheet will be useless.
My question:
Is there some way to lock or protect text form fields such that the rest of the document is editable? I essentially want to have the inverse of a "text form field only" protection.
Alternatively, is there a better way to approach this project? I'm thinking of leaving the spreadsheet as is, but including a "reset" button bringing the template back to it's original state if anything breaks. If I did this method, this would require there NOT to be an external file. Attempts to do this so far have proven unsuccessful.
My general methodology/algorithm goes as follows:
Open the reference document
Replace all the text form fields via bookmarks with plain text,
making sure to reassign the bookmarks afterward (so as to not lose
them if they run the macro more than once).
Save the embedded document as a .doc with the inputs inserted
Replace all bookmarked inputs with text form fields to return the
template to its original state
Any information would be IMMENSELY appreciated. I am slowly running out of time and am feeling stuck.
Many thanks!
-Sooji
I'm creating a program which extracts a docx file, displays it in a Javafx graphic interface with buttons in place of flags put in the docx, and when one puts on it, it modifies the docx taken in input.
I'm using the docx4j API for extracting and modifying the document.
The problem is that the program fails if i take in entry a docx generated from Microsoft Word. I'm forced to use an artifice.
I'm taking my docx made on Word, then i load it in Google Docs and I use the "Download in .docx format" option. If i directly put the docx from Word in my program, it fails.
I noticed my Word file was two times lighter after being passed trough google doc. Same, if I tale a docx file downloaded from Google Docs, if i open it in Word and modify one letter and save it, he becomes two times heavier. For the record i use word 2008.
That's it, so I'd like to know if someone know what explains this difference.
Thanks
I have a Microsoft word document with 58 pages when I generate pdf file with word itself or doPDF or other softwares, they generate pdf file with 61 pages. How can I solve this problem.
My document written in Persian language.
Word loves to reformat the document whenever something is changed in the printer settings (such as selecting another printer). You might make sure that you have the printer driver used for doPDF active when you edit the document, and invoke the Print command.
You may also make sure that the page sizes selected in the print dialog correspond to the one of the document.
You can also, make sure that you have written the document using word's ability to end (break pages) that way you will make sure that the pages you have are not moving, especially the figures.
I have written a code which utilizes Word Automation Service in order to convert the .DOCX file to the .PDF. I have noticed that in case the Word document contains a table of contents, its links are removed in the PDF. This is very bad for my business case.
On the other hand, manually opening MS Word and saving the same document as PDF preserves the links in the table of contents. This is the behavior I am looking for, but I want to keep my code independent form having MS Office Word installed on the machine running my code.
Has anyone had the similar issue and was anybody able to resolve it?
In my case, i found out that this is something related to Job Settings property. Try to comment or remove this line of code if you have one:
jobSettings.UpdateFields = true;