Find A Specific Word From Word Document...
Hi All,
Need help...
i have a word doc. it contains some data.. and bottom of the page it contain the following paragraphs. its single page word doc. Code:Very truly yours, sam Officer
From vb i want to find word, the next line of the 'very truely yours'. like here in this example i have to capture the value 'sam'.
Any idea how to get that..
Thanks Balakumar
Edited by - pmmbala1976 on 6/2/2004 4:45:19 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Word: Counting A Specific String In A Word Document
Hi all,
After visiting the Word FAQ I couldn't find any clue for my query:
I would like to count (in VB) how many times the string "Yesterday"
appears in a word document I am working on.
By using the manual Replace function (replacing "Yesterday" by "Yesterday"),
Word tells you how many replacement it has done and therefore how many
instances of the string "Yesterday" were in the document.
Can anyone point me in the right direction about using VB to find out
how many times "Yesterday" appears in my document, please?
Many thanks
Francois
VB In Access To Find And Format A Word In A Mailmerged Word Document
I use my Access data base to create mail merged letters to our customers. Not only are the names etc stored on the database I also store the content of the letter in memo fields. I have occasions where I want the newly created letter to have some words bold. After having VB code open the main document, mail merge then close the main document I run the following code. It works the first time round, the specified word becomes bold. However after closing the letter and running it a second time the new letter opens but no changes are made and I get an error. "Run Time error '462' : The remote server machine does not exist or is unavailable". This gives me a Debug option. When selecting debug The first row in this code is selected.
With ActiveDocument.Content.Find
.ClearFormatting
.Font.Bold = False
.MatchCase = True
.Text = "SATURDAY"
With .Replacement
.ClearFormatting
.Font.Bold = True
.Text = "SATURDAY"
End With
.Execute Format:=True, Replace:=wdReplaceAll
End With
If I leave the new letter open and re run it the code opens a second new letter with no errors, however it does not make the changes to the newest document only the first new document it finds. ie If I then close the first one created and rerun it the second document will have the changes made and the third one does not change. The error only occurs once I have closed all new documents and try to open another letter.
Hope someone can help
MSAccess Database DOA
Opening A Specific Word Document
Is it possible to open a specific Word document using VB having obtained a Filename using a CommonDialog box. I am attempting to conduct a search of coded word filenames, filtered on the search criteria, into a Common Dialog "Open" box. I can select one of the returned files and obtain the Filename, but cannot open the required file. I am using VB5, however I note that the method "OpenFile" is available in VB6. Will this open the required Word document ?
Placing Information In A Specific Area Of A Word Document
I've read Learn to Program Visual Basic Objects from John Smiley - on using Word objects with VB. I've read the Word 101 Tutorial and done a searching on editing Word documents but I still can't find what I want. I would like to place text in a x,y position on the Word document. Basically I will calling information from an Access table and as I loop thru it I want to be able to place the text within an already established document. Through all my research all I see to place text in a specific area is the vbTab - used in connection with the Selection.Type Text Text:= code.
Once I loop through each record, this information will be placed side by side with other information that is already formatted into columns! I was hoping to have the information placed in Word similiar to Excel with a specific reference x,y (like to a cell). Any input is appreciated!
Thanks for the help!
Sincerely,
Stephen LeCompte Jr.
Find A Specific Letter In A Word
I need to know if there is any sort of Visual Basic equivalent to the Javascript CharAt() function.
It's for a hangman game. I need to be able to get the length of the word too - that's another thing I can't do!
Thanks in advance...
How To Find A Specific Word In A Variable?
I need a simple way to do this..
(like the indexof(blah) in ASP / java)
if i have the variable "MSG this message"
how can i make it find the "MSG" part in that variable.
and if there is a "MSG" part in the variable, how can i make it read only what is behind the MSG part...
So that i can use this as a "command" in a text based program.
like if i write "MSG whatever text there is to write" into a variable (textbox) then it sees the MSG and takes the rest and produces
MSGBOX "whatever text there is to write",,"MSG command"
How can i do this? ?!?!?
Please provide whatever example you might have on this...
Thanks... in advance -AlexData-
Use Macro To Find A Specific Word In Excel
Hi all,
I need the help as currently i have created a vb program which link to excel worksheet. The program has to search for example "FREIGHT" word in EXCEL column B. If the column B has such "FREIGHT" wording, the program should stamp "FOUND" in column C else nothing will stamp in column c.
I can use below script to find the "FREIGHT", but my question is how to set "FOUND" in column C if the "FREIGHT" wording is found in column b? Anybody got any clue on it ?
ExcelSheet.Columns.Find(What:="FREIGHT", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
Please help!
Thanks!
From,
Siaw Ch'ng
Find In Document Using VB6 And WORD XP
I would like to pass a function the path to a word document and a search string. All I need back is a true/false as to if the search string was found in the document. Here is what I have:
Code:
Private Function SearchDocuments(DocumentPath As String, SearchString As String) As Boolean
Dim bReturn As Boolean
Dim objWdApp As Word.Application
Dim objWdDoc As Word.Document
Dim objWdRange As Word.Range
Set objWdApp = New Word.Application
Set objWdDoc = objWdApp.Documents.Open(FileName:=DocumentPath)
objWdApp.Visible = False
Set objWdRange = objWdDoc.Content
With objWdRange.Find
.ClearFormatting
bReturn = .Execute(FindText:=SearchString)
End With
SearchDocuments = bReturn
Set objWdRange = Nothing
Set objWdDoc = Nothing
Set objWdApp = Nothing
End Function
When I run this I get an (Automation Error -> Object is not connected to Server)
Any help would be greatly appreciated!
How Do I Find A Specific Word Or Number Inside A Text Box
How do i find a specific word or number in a text box and then maybe replace it.
e.g.
the text box contains "This is a test"
I want to find "is" and replace it with "was"
also the text that is in the text box is text that is entered so I don't know what the text is when I make the program.
Thanks in advance.
How To Find A Button Based On Its Text , A Specific Word??
hii community,
i've been trying for this for last 1 week. now i'm able to do it in diffent fashion (using sendkeys etc..) but that is not efficient. So i want to follow a general procedure. Fot that i need to do the following.
how to find a button in a webpage based on its text , a specific word (this word may be a link to another page) in a webpage like ' compose', 'sentmail' etc. And perform the click operation . I can do it myself. All i want to know is how to find either a button or a specific word??
Please help me.
thanks.
Find A Word In A Text Document
hi all, I need some help. Urgently I need a template of vba code which searches into a .txt file for a word (e.g. "London") and comes back with the following result: the sentence of where this word is (starting from the word, finishing at the first full stop),each sentence in one line 1. 2. 3. etc respectively. Then I need the program to save this to a table in access.
Thanks a lot for the help
Manolos
Find Text In Textbox In Word Document`
I can find text fine when the text is in part of the basic Word Document using the .FIND, .Execute methods of the Word Document Object, but if the text is in a textbox, I can't find it. Is there a way to do this?
Find Curser Position On Word Document
Hi
Is there any command that will show me an integer/long value for the curser or scroll bar position in a word document
so that when i find a word in the document i can tell if it before or after a position stored in a variable?
Find/replace Text In Word Document From Vb?
Hi,
I need to be able to automate a find/replace function from within VB for a specific Word document.
For example, I have a document named Document1.doc. There is text in it as follows:
Hi, my name is <NAME>!
From within VB, I want to be able to replace the <NAME> with "Dan".
The values would not come from a database, it will be hard coded, so no need to show any data connectivity code. Just a plain and simple find/replace function.
Any help would be appreciated..
Dan
Find A Custom Color Hex Number From Word.Document
i have this document object:
Code:
Private WithEvents WordApp As Word.Application
Private WordDoc As Word.Document
and i need to find the HEX expression of a user customed color i.e.
Code:
fontcolor = .Paragraphs(iparag).range.Words(iWrd).Font.Color
there are properties like colorIndex, DiacriticColor. but they all seem to be inside indexes of Word.
in the application itself, there is a divide to the three main colors, but i can't get to them through this objects.
it really is annoying, but must be simple enough.. please help
How Can I Find The Position Of Bookmark In A Word 2000 Document?
I've been struggling with a particular report for a while now, and hope that the VB community can help me with this problem. I want to find the position of a bookmark or form field in a word document. (I'll explain my situation below)
I have attached a jpg with an example of what I am trying to do.
The report has a header always at the top of the first page. (I can't use a header though because I have several form fields in it, but thats no biggie). Usually, the header + body + footer will fit on a single page and nothing goes wrong. However, when the body causes the footer to go to the next page, I am required to show this footer only on the bottom of the last page of the report (which probably will never be longer than 2 pages, but I don't want to assume that).
Initially I thought this could be done with tables and continuous sections in Word, but I haven't had any luck.
Why do I want to find the position of a form field or bookmark? At the beginning and end of the footer section, I've placed textboxes. (txtBegin and txtEnd). I think that I can add a carriage return until I determine these boxes are no longer on the same page, and then I can delete the last carriage return and this footer will sit perfectly at the bottom of the page.
These are my thoughts for a solution. I'm hoping that someone can help me find a way to determine the line or page the bookmark is located on, but I would be welcome to any suggestions at this point.
Thanks for any help the vb community can provide.
Tyler Dueck
dueck@hadmacker.com
Find A Custom Color Hex Number From Word.Document
i have this document object:
Code:Private WithEvents WordApp As Word.Application
Private WordDoc As Word.Document
and i need to find the HEX expression of a user customed color i.e.
Code:fontcolor = .Paragraphs(iparag).range.Words(iWrd).Font.Color
there are properties like colorIndex, DiacriticColor. but they all seem to be inside indexes of Word.
in the application itself, there is a divide to the three main colors, but i can't get to them through this objects.
it really is annoying, but must be simple enough.. please help.
How To Find Out Whether A Word Document Is Already Opened Or Not From Visual Basic?
hi,
iam working with a search application.
my application will search for the document asked for and displays the full path.
if i click on the path the word document will be opened.
if i again click search then its not giving any error,but its hanging up.
its not giving any error like "permission denied",since the word document is already opened.
so i want to know is there any way to know whether a document is still opened or not.
please suggest me ....
regards
varma
Opening Word Document From Excel When The Word Document Is Read Only
I'm trying to open a Word document from Excel and have hit a snag. The file I'm trying to access is Read-only and the code stops when the "This file is read-only..." prompt displays. How do I get past this? Here's the code that I have so far (thanks to some help from this forum):
Code:
Sub OpenAndPrint()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim stPathName As String
stPathName = Range("B4").Hyperlinks(1).Address
If Dir(stPathName) <> "" Then
Set wdApp = New Word.Application
wdApp.Visible = True
wdApp.DisplayAlerts = wdAlertsNone 'Tried to turn off the prompt, but it didn't work.
Set wdDoc = wdApp.Documents.Open(stPathName) 'Code stops here and waits for the user to respond to the prompt.
Set wdDoc = Nothing
Set wdApp = Nothing
Else
MsgBox "The file does not exist!", vbInformation
End If
End Sub
Find Whether Selected Object Is Excel Sheet In A Word Document!!!
Hi,
I want my program to detect an excel sheet. Actually I'm developing a parser for word document and I'm moving from Top to End of doc. I'm working on selection property and check for the predefined book marks for line, table, etc.
Code:
Selection.bookmarks.exists(" able")=True
But I've not found any way to detect an excel sheet during parsing. Even bookmarks do not work for excel sheet. Hope I'm clear. Can anyone help me out?
Thanks,
Subha
Find Whether Selected Object Is Excel Sheet In Word Document
Hey All,
I want my program to detect an excel sheet.
Actually i am developing a parser for word document...and i am moving from Top to End of Doc. i am working on selction property...and check for the Predefined bookmarks for Line, Table etc.
Selection.Bookmarks.Exists("Table") = True
But i have not found any way to detect an Excel Sheet during parsing. Even Bookmarks do not work for Excel Sheet. Hope I am clear
Can any body help me
Merging/Importing Word, Excel, Powerpoint And Visio Files Into A Word Document
Does anyone know how to do this or know of a website that has source code that does this? I can't find anything anywhere.
Each Page/Worksheet/Slide goes on a seperate page. Print formatting is retained (landscape/portrait) and if the imported Page/Worksheet/Slide is larger than the page im merging/importing to, it should auto-resize to fit the page.
Thx.
Reading The Word Document From Visual Basic Without Opening The Word Applicaiton
Hi
I need to access the word document from visual basic without opening the word application. I can do this by opening the word application. Is there any other way to read a document from vb.
I need to search for a particular word in the document without opening the word application.
Waiting for your reply,
thanks
Mohan
Error 4605 Calling Word.Document.Save With Word 2002 SP1
I have a test VB6 exe project with a WebBrowser control, called web1 (added via Project, Components, Microsoft Internal Controls). My project also references the Microsoft Word 10.0 Object Library.
As well as the WebBrowser control, my form has a Save button (cmdSave). Here is the complete code:
Code:
Private g_objDocument As Word.Document
Private Sub cmdSave_Click()
g_objDocument.Save
End Sub
Private Sub Form_Load()
Dim strFileName As String
strFileName = App.Path & "WordWrapper.doc"
web1.Navigate strFileName
End Sub
Private Sub web1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
Set g_objDocument = pDisp.Document
End Sub
The idea is when I run the exe, it loads a Word document into the WebBrowser control. This document is also assigned to
a global Word.Document object, g_objDocument, when web1 navigates to it. The problem occurs when I try to save the document (in cmdSave_Click). I get the error:
"The Save method or property is not available because this document is in another application."
This error occurs with Word 2002 SP 1 (on Windows XP), but not with Word 2000 SP3.
Please help.
Load Word Document In VB Form And Use Word's Zoom Features - Help
Hi
I've this VB6 application where I can opt to load a word document or scaned 8X11 image of a paper form on the VB form and let user write or draw using a tablet. Since screen doesn't have enough space to show complete form at one time, I need to zoom it down to fit the screen so it get mapped properly with tablet. Once user is done drawing or writing, I need to bring the document or image back to original size and print it or save it.
I don't know where to start. Plese guide me about the best way to accomplish this. Thanks.
Convert Html To Word Docuemtn Using The Word Document Object
i ant in vb6 to open an html page
and convert and save it as word *.doc
how can i do this?
and is it possible to open the html file from the internet with a give url so i will be :
open html document from www..../1.html -> save as 1.doc
thnaks in advance
peleg
Load Word Document On VB Form And Use Word's Zoom Fetrures - Help
Hi
I've this VB6 application where I can opt to load a word document or scaned 8X11 image of a paper form on the VB form and let user write or draw using a tablet. Since screen doesn't have enough space to show complete form at one time, I need to zoom it down to fit the screen so it get mapped properly with tablet. Once user is done drawing or writing, I need to bring the document or image back to original size and print it or save it.
I don't know where to start. Plese guide me about the best way to accomplish this. Thanks.
Word Automation - Retaining The Numbering Format In New Word Document
Hi all,
I am using word automation to read a word document. I use word automation to read the word document page by page and paste the contents of each page in a new document.
The problem i am facing is, the word document which is read contains Heading1,Heading 2 etc and these are numbered. When I paste these pages onto a new document the numbering is not retained. (Eg., if my Heading1 number is 2.1 when i paste it in a new document the Heading1 number is shown as 1.1)
VBA: Creating Word, And Sending Data To A Word Document Using Ranges
The following code works fine when it is executed only once in any instance of the VB program.
It is OK provided I do not close Word, and it will create multiple instances of the document into the same instance or word.
Screen.MousePointer = 11
GetWord2
WordApp.Documents.Open ("C:Program FilesWill WizardTemplatesClauseLib.doc")
set MyDoc = Documents.Open(FileName:="C:Program FilesWill WizardTemplatesClauseLib.doc")
set FldRng(1) = MyDoc.Range(Start:=MyDoc.Bookmarks("Name").Range.End, End:=MyDoc.Bookmarks("NameEnd").Start - 1) 'read bookmarks into range object variables
FldRng(1).Text = ClauseHold 'put the stuff into the document
WordApp.ActiveDocument.SaveAS FileName:=("C:Program FilesWill WizardTemplates emp" & Trim(Str(TMPNum)) & ".doc")
WordApp.Application.Activate
WordApp.Visible = true
set WordApp = nothing
set MyDoc = nothing
Screen.MousePointer = 0
Command8.Enabled = true
Exit Sub
If Word is closed, and the code is executed again, an error occurs "the remote server machine does not exist or is not available" The only remedy for this is close and re-start the VB application containing this code.
The GetWord2 et-al Function codes are: (which is stored in a module)
option Explicit
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (byval lpClassName as string, byval lpWindowName as string) as Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, byval lParam as Long) as Long
public WordApp as Word.Application
public WordWasNotRunning as Boolean ' Flag for final word unload
public Sub DetectWord()
' Procedure detects a running Word and r
' egisters it.
Const WM_USER = 1024
Dim hwnd as Long
' If Word is running this API call retur
' ns its handle.
hwnd = FindWindow("OpusApp", vbNullString)
If hwnd = 0 then ' 0 means Word Not running.
Exit Sub
else
' Word is running so use the SendMessage
' API function to enter it in the Running
' Object Table.
SendMessage hwnd, WM_USER + 18, 0, 0
End If
End Sub
public Sub GetWord2()
' Test to see if there is a copy of Micr
' osoft Word already running.
on error resume next ' Defer error trapping.
' Getobject function called without the
' first argument returns a
' reference to an instance of the applic
' ation. If the application isn't
' running, an error occurs.
set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 then
WordWasNotRunning = true
else
WordWasNotRunning = false
End If
Err.Clear ' Clear Err object In Case error occurred.
' Check for Microsoft Word. If Microsoft
' Word is running,
' enter it into the Running Object table
' .
DetectWord
If WordWasNotRunning = true then
'set the object variable to start a new
' instance of Word.
set WordApp = new Word.Application
End If
' Show Microsoft Word through its Applic
' ation property. then
' show the actual window containing the
' file using the Windows
' collection of the MyWord object refere
' nce.
WordApp.Visible = true
WordApp.Application.WindowState = wdWindowStateNormal
Screen.MousePointer = vbDefault
End Sub
do I need to close the document? = deactivate something?
I would like a code example on how to fix the above, else, any suggestions, ideas...
Jason.
Selecting A Particular Word From A Word Document (.doc) Through Visual Basic 6
I am a developer using Visual Basic 6. One of my program accepts some values through text boxes and then creates a Word document. The text boxes are optional, and the created Word document contains only non-empty values along with appropriate labels. I am able to apply styles (bold and underline) to entire paragraphs. But the user wants me to apply bold formatting only to values entered by him and not to the labels which describe those values. Please help me.
Thank You.
Lalit Kumar Barik
India
Open A Document Word From A Template Of Word
Hello, I'm working in Visual Basic 6 and I want open a document word. But this document must be from a template of word (its name is Informe).
I do it with the code
Dim objWord As Word.Application
Dim objDoc As Word.Document
Set objWord = New Word.Application
Set objDoc = objWord.Documents.Add("C:Informe.dot")
It's ok but I only see the document, I want to see the menus of word,....
If it isn't possible can you send me the code to print this document?
Thank's and sorry for my poor english
Word Form >> Process >> Word Document
Please be gentle, as this is my first foray into VBA. To make matters worse, I'm not a programmer, just someone who needs to get something done. My guess, based on what I want to do, it that I can do it easiest in VBA, but I am hoping this forum will help flesh out that answer for me.
In a nutshell, I am trying to create a document (possibly a Word form?...) that has a definite format with fields to be filled in (mostly numberic values, checkboxes, or free text). This form will be filled out by our techs at a customer site. They may do this 'live' with Word open, or they may print it out, then fill in the document later from their handwritten copy.
Next, I would like to 'process' their answers by feeding some information directly into an output document (Word hopefully). Now, some fields like name, address, etc... will go straight over and don't require manipulation. Some other data will need to be processed.
For example, if the tech fills in 34, I might want the output document to put 'this text' under a certain heading. If it is >34, then some other text, less, maybe no text. I'd also like to be able to change some graphics based on limits. i.e. if the value is less than this, insert this picture into the output document at a specific location, if not, insert this picture.
So, in general, before I go down the road of learning a language... do the members here think VBA would be a good choice for this? Would I 'read' from the input document in Word Excel, process in Excel and then pump data out to the output docment, etc... I am looking for advice whether this is;
1. fairly straightforward, understanding that I would need to learn some VBA.
2. possible
3. a good choice. i.e. would another language, or a pre-done software make a better choice.
My contraints are that my company has Office 2000 rolled out, WITHOUT Access. We use Lotus Notes and Access is apparently frowned upon. I am an optimist, so I expect it's possible with careful design and help from the experts who've been down these roads before.
Thanks in advance for any help, insight, advice or code.
Regards,
John
Opening A Word Document With Word From Excel
i want to have a part of an excel macro where it opens up a word document in word (so it would have to open the application itself) and then be able to do everything that i can do using the word vb editor. is there some easy way to do this?
Change Word On The Footer Of A Word Document
I like to change the word "Version 1.0" to "Version 2.0" on every page on the footer of a word documents using VB6 with the word document minimised when the program is making the change. Does anyone know how to do this? Thanks.
Tricky Search Of A Word In A Word Document...
I need to create a VB project that searches a word in a
Microsoft Word document, counts the number of apearences
and the page and row where the word apeared.
Ex.
Suppose I need to search the word: "please"
The result should be of this form:
please - 1/2,3 ; 4/1,13
This means that the word "please" was found in the document on the line 2 and 3 of the page 1, and on the line 1 and 13 on the
page 4.
Please tell me if this can be done. I need it ASAP.
Thanks.
RichTextBox Find Then Show Word After Found Word??
Confusing hey!
In english what i want to do:
I can find the word in a richtextbox i'm after but what i want it to do is return the letters after the found word up until it comes to a semi-colon.
I.e
Username=blahblah;
I can find username= i want to return the blahblah bit!
b
To Find A Word In MS-Word With Files Having Extension .DOC (new Try)
I tried in the following way
Dim Appword As Object
Dim Wdoc As Document
Set Appword = CreateObject("Word.Application")
With Application.FileSearch
With Appword.FileSearch
.NewSearch
.LookIn = "C:My Documents"
.SearchSubFolders = True
.TextOrProperty = txtSrch.Text
.FileType = MsoFileType.msoFileTypeWordDocuments
End With
I get error .filetype =msofiletypewordDcouments
or what should i do with .filetype
Pl Help
Regds
Sam F.
|