Find A Word?
i was wondering if this is possible. lets say i got these words in text box Code: risks mcnuclumerbanie assing malings publust undly connecian puss cationneratern planess bever victivelentate shad hard sputers advaties puls den salve paracco
and program has to find a work i give him and for example i give program to find hard in the text box. if it finds it then it says a msgbox that word was found and if it doesnt then do nothing.is it possible?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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
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.
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
Basic Word - A Simple Find, Print Current, Find Next, Print
This is a really simple code used as a macro in Word that finds, prints the current page it found it on, finds next, print, etc. The problem in my code is that I need to find a way for it to stop at the end of the page <the loops i've put in won't stop.. i dont know the end of page function ?? or something along the lines>. So basically I just need this to keep looping until it reaches the bottom of the page. Here's what I have :
Selection.Find.ClearFormatting
With Selection.Find
.Text = "NO"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=False
Thanks in advance for your help.
Jeff
A Little Help With .find In MS-Word
Hi there! Just an easy beginner level question here. I'm trying to create a tiny search engine for a single word file. Here's how the program works: I enter a keyword into a textbox. That keyword is set into a pre-declared variable. All the program has to do is see if the keyword already exists in the word file and if it does then returna message box or something with a yes and if not then one with no. I've got most of it figured out.
The only thing giving me problems is the .find function. Here's the code I've got so far:
Code:
Private Sub CmdSearch_Click()
Keyword = TxtKeyword.Text
Dim App As Word.Application
Dim Doc As Word.Document
Dim Range As Word.Range
Set App = New Word.Application
Set Doc = App.Documents.Open(FileName:=Path)
Set Range = Doc.Content
With Range.Find
.ClearFormatting
.Text = Keyword
End Sub
As you can see, I've only included the sub with the search function in it. Keyword is a string that I decalred globally. What I need to know is what I should do next. I know how to replace text in a word file and stuff but how do I get the darned thing to return a yes or no message box. Any help is greatly appreciated. Thanks.
- JD.
Find Whole Word Only
Hi All,
I am trying to stimulate the "Find Whole Word" option similar to the one we have in MS Word to perform Find/Replace of abbreviations in Excel files. I was able to come up with the following:
*****************************
Code:
Sub Test()
Dim WorkRange As Range
Dim c As Range
Dim Punc As Variant
Dim Pos As Integer
Dim x As Integer
Dim y As Integer
Dim Str As String
On Error Resume Next
Set WorkRange = Selection.SpecialCells(xlCellTypeConstants, 2)
If Err <> 0 Then
MsgBox "No cells found"
Exit Sub
End If
On Error GoTo 0
Dim Ans As Variant
Ans = InputBox("Replace what", "Replace whole word")
If Ans = "" Then Exit Sub
Punc = Array(" ", ",", ";", ":", ".")
For Each c In WorkRange
For x = LBound(Punc) To UBound(Punc)
For y = LBound(Punc) To UBound(Punc)
Str = Punc(x) & Ans & Punc(y)
Pos = InStr(1, c.Value, Str, 1)
If Pos > 0 Then
c.Value = WorksheetFunction.Substitute(c.Value, Ans, "")
Exit For
End If
Next y
Next x
Next c
End Sub
************************************
However, this code has the following problems:
1) The code works well only if the term is preceeded by and followed by another term. If the term NS comes in the starting or the end of the cell, the replacements are not affected.
2) Also, my excel sheet had "this is good" in one cell, "is this good" and "good is good" in the other cell. When I run the macro to replace "is" with X, the text in these 3 cells becomes "thX X good" and "is this good" and "good X good" respectively.
Can someone please help me out in this?
Regards,
thevbgirl
Find A Word
whats the best way to search for a word in a string because i was finding a word in a string using InStr and it said it was in the string but it wasnt.
if i was searching for the word "car" it would say it was there because of the word "carpet" being in the string.
Find Word
How do you find a whole word in a string?
Thanx in advance!
Find Whole Word Only
I want to find, if a whole word exists in a string. For this reason I am using the function Instr. The problem is that via this method I don’t take the appropriate result.
For example I want to see if the word “auto” contains in a string. Lets say that this string is this one: “My automobile is the best”.
If I use the Instr(1, “My automobile is the best”,”auto”), I will take a positive number but my target is to find out only the existence of the word “auto” as a separate word, like similar with the option of the Visual Basic Find where you can define to search for “Find Whole Word Only”.
Find A Word
In a Richtext Box in want to find a word between two space
how can i find this
Find the word between two space
ex.
vbForums vb vbForums
in want to find "vb" in between the sentence
msatyanarayan@yahoo.com
Find Word On Row 0
Hello
This is bit of a tough one and that is why i am here asking for help from the professionals.
I have a datagrid connected to a excel spreadsheet. The database has 6 row ranging 0 to 5 and nearly a hundread columns.
What i need is to find a word on row 0 and display. But the only criteria i have to work with is the row number where a character is held and the character on that row.
For example:
0 Hello Bye Maybe Yes No
1 f t h s u
2 u a b t k
etc......
So for example if i have the row number 2 and i know the character, which for example is t. So i need it to find Yes.
I have tried a loop, which works. But this takes far too long.
I have been suggested to use a select case but im not too sure if this will work.
Any suggests will be appriciated.
Thanx for your time
VBA + Ms Word Find All
Hi ,
i want macro for Find all functionality in ms word to make my
application fast. now i written find.execute method in do while loop. but it
is very slow for more than 200 docs.
urgent....
Thank you.
Karunakar Gadde
Find A Word From Doc
Hi,
i have a word doc with single page. it contains data like..
Very truly yours,
sam
Officer
from vb i want to find whats the name present in officer place. i mean the next line of the 'very truely yours'. like here in this example i have to capture the name 'sam'
any idea how to get that..
Thanks
bala
Find Replace Word 97
Hi ,
I currently have a little bit of code written as a macro in word
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = strFind
.Replacement.Text = strReplace
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute replace:=wdReplaceAll
, It works fine but I want to be able to insert larger strings. A large string will course this to crash. How can I insert a bookmark at this section then insert the large string as several small chunks? Would this be the right approach?
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!
Using Find And Then Highlighting The Next Word.
I've read and experimented with VBA 101 Tutorial. My task is to Find a word and then highlight the word or words after it. There maybe 1 or more words, but there is always a Paragraph symbol at the end of the line (when I show Paragraph formatting). IOW, I need to Search for a word and then select and highlight the very next character to the end of the line. Once I select the desired word(s) I need to make it Bold. I've figured out how to make it Bold, but selection and highlighting is the tricky part.
Thanks in advance!!!!!!
Find Replace In Word
Hello All ! !
Can you please help me ?
i have a doc file and in the doc file there is fields like <name>
i need to paint all the text in the fields
i have 3 kinds of fields ( < field1 > ,<< field2 >> and <<< field3 >>>)
how in a macro can i paint the each field in diffrent color
Thank Very Match
eric.
Find/Replace In Word
Hello. I am attempting to fill in a user-created template in a word document from my VB program by replacing certain pre-defined keywords with data from my program.
I started out using Word 97 (uses the msword8.olb) and vb6. I found an example of how to do this in the Vbawrd8.hlp file, and even verified by capturing macro, which generated essentially the same code.
With ActiveDocument.Content
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
n = 0
Do
With Selection.Find
.Text = FindText(n)
.Replacement.Text = ReplaceText(n)
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
n = n + 1
Loop Until FindText(n - 1) = "<STARTTEXT>"
End With
However, when I tried it, it crashes the VB devel environment repeatedly.
Just for kicks, I tried word 2002 (olb 10), and it works ok. Problem is I need it to work under virtually any version of word from 97 up, and windows 98 up.
Has anyone ever overcome this problem, or at least know which versions of word I can expect will work??
Thanks in advance.
Find Next Macro For Word
One thing about MS Word drives me crazy. Well, lots of things, but this one is particularly maddening.
In every other Windows text editing program, the [F3] key is "find next.' Once you've done a search, you can hit [F3] to step through the file, repeating the Find. It works in WordPad. In Notepad. It works in MS-DOS Edit. Probably worked in WordStar. Heck, my Linux editors have this feature.
Not MS Word. Its default F3 function is some obscure thing I've never used, never will. I think you need a three-handed function to evoke a Find Next.
What would be the most efficient macro to assign to F3 to execute a Find Next? I have some ideas, but I'll bet it's a one-liner.
Find If Label Contains A Certain Word
I have for example a label, with the text "Davy Depuydt"
now I want that when I insert "puy" in a textbox, and press a search button, that the application will recognize that my label contains "puy"
Please Help An Idiot Find MS Word
I want to have menu options on my prog to launch MS Word, Access, Excel, Outlook and Power Point. Some people install these apps to different locations, meaning that the way I know how to open it, supplying a UNC path to the EXE file wouldn't work on every PC. Could someone please prodive a line of code to search a HDD for the executable? Please help!!! PS... I'm a VB NEWBIE!
Find Unique Word
What would be the best way to search through a string and find the number of times a word occurs.
such as
"The" = 2 times
"Bongo" = 10 times
....and so on
Matt
InStr To Find My Word
I'm use InStr to find my word
Code:
example: Text1 = "abcdefghijk"
if use InStr(Text1.Text, "cd")
return_Text2 = "3"
but If find "cd" that word
word****ans
bacde = true
fffsa = false
bccxdd = false
Code:
If return_text > 0 Then
'word find Else
'not find
End If
But If hope NOT use 0,1,2,3 is oke?
same of dir *cat*.*
will show all aacataa.txt; bbcataa.txt......
this is use InStr ?
thanks!
Textbox Word Find
I'm making my own HTML editor and i'm stuck!
i'm loading files through my own file load/save structure.
it can load HTML and TXT files into a simple textbox.
if you save the file your selected colors ETC will be added to the file,
i want to check for the first XX ( xx being an number of characters ) is the selected colors are allready loaded or not...
how to...
--------------------------------
example
text.txt example
<HTML>
<HEAD>
<BODY>
rest of file...
i want to read out <HTML> to see if the codes are added
--------------------------------
Coasterguy2000
-----------------------@iceplug
XX is indeed a number like 52, or 99
how do you use the inStr() function?
en what does it do, i mean i don't really need the position, only confirmation is it's there.. like (i normal english)
If 'String' Is there Then
do not include piece of text
Run subroutine
End if
--------------------------------
Find A Word By SQL Query In VB
Hello I am trying to find the word in a database. So I wrote this piece of code and it works. But I am still not sure if it fınds all possibles.
Lets say we want to find all "do" in such sentences.
do you do What I do?
I do it as you do.
do it
he will do
I want to be sure that query finds "do" in all possible positions. what changes can be made or is there a shortest way*
WHERE ENG LIKE '" & myphrase & " %'
OR ENG LIKE ' "& myphrase & "%'
OR ENG LIKE '% " & myphrase & " '
OR ENG LIKE '% " & myphrase & " %'
OR ENG LIKE '% " & myphrase & "'
OR ENG LIKE '% " & myphrase & ".'
OR ENG LIKE '% " & myphrase & "!'
OR ENG LIKE '% " & myphrase & "?'
thanks in advance
Need Help... MS Word Find/replace
I have done searches for code examples on how to find/replace text in an MS Word doc, and have recorded a macro to do this. But when I put the code from the marco into my VB app, it NEVER works! I don't understand what is going wrong. I have control of the doc, I am able to type text into it but not able to use find.
Any suggestions?!?
Find A Word In A Textbox
Heh, I seem to be having trouble making a find routine that runs quickly. I have a word in a textbox and in another textbox I have a large (10+ mb) textfile. I just want to find the one word in the largly filled textbox and report how many times it appeared. Any ideas?
Find The Corresponding Reserved Word
The "End If" to "If", The "Loop" to the "Do" and so on
To have the cursor on the "If" and hit a key combination on the keybord or something to find the corresponding "End If"
I have done it in other languages, is it possible in VB?
Find If Word Is Open
I write an application that open MSword , I use GetObject:
Set objWord = GetObject(, "Word.Application")
but if MSword is close it raise an error (429), then I use this (after the ErrHandler tag):
Set objWord = New Word.Application 'Create New refernce for Word
Resume Next
I wonder if there is a way to find if MSword is open , before i call GetObject ( I dont want to use this :
Set objWord = GetObject("", "Word.Application"))
Thanks
Word Like Find Functionality - NEED Help
Ok, I need help! This has had me & the rest of the office stumpted all afternoon.
What I'm basically trying to implement is funcionality the same as exhibited by Word's 'Find', i.e. a form ('B') is spawned non-modally by the main form ('A'). Both 'A' and 'B' can respond to user actions (editing or whatever). 'B' contains a button 'Cancel' or something similar that kills it. The only problem is that somewhere there's a reference hanging round, because the form 'B' NEVER terminates!
Has anyone written anything like this or have any idea how to go about it? Please help!!
K
[Edited by kleve on 05-18-2000 at 04:59 PM]
Find The Initials In A 3 Word Name
Im new here and having trouble getting this one program to work. I found a questionon this site here which is just like what i need to do, but i need to find the first letters of the 3 words in the textbox. omeone showed me how to do it with functions, but that didnt help because i dont know functions.
so if somone could explaing it to me, id really apperciate it.
thanks
Find A Word In Word
Hi there,
I have two questions, but they are very much related to each other:
1.
Is it possible to check a word document (over 100 pages) for specific words with a specific color and fonttype.
2.
Is it possible to split a word document in sentences, and check that sentence one word at a time.
Kind regards.
Find Word, Delete From File
Can someone tell me a simple way to do this? I have a text file with IDs in it. I want my VB program to go through this text file and delete certain IDs. Thanks.
Where Can I Find A Practice MS Word Exam?
Hello! I am looking for a practice MS Word exam so I can prepare to take a certification test. I was asked to an exam to verify my skills with MS Word in order to qualify for a particular job.
I am quite experienced with MS Word, but you can never be too prepared! There are so many features to Word, there are a number I have never needed to use.
Does anyone have any suggestions or links to websites?
Thanks!
-Sherpa
How To Find The Start And End Position Of A Word
I am now writing a VB program for Word. I want to write a program that, a user don't need to highlight the whole word and rightclick. The user just need to click any position between a word, then rightclick, then the program can know the start and end position of the word.
Now I was using the following code to do so:
Selection.MoveLeft unit:=wdWord, count:=1
Selection.MoveRight unit:=wdWord, count:=1, Extend:=wdExtend
startPos = Selection.Range.Start
endPos = Selection.Range.End
However, the above code will highlight the whole word. The cursor position has been changed. I don't want ithappen. I just want the program determine the position without highlighting the word and the cursor position is unchanged. How can i do so?
Thx a lot!
Find/Highlight Words In Word Doc?
This is something I found in Word 'help'. It'll change all instances of what I find, but I have no luck finding the syntax/command to highlight the hits rather than changing them. Can you help me out?
With ActiveDocument.Content.Find
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="employer_lname", ReplaceWith:=" EMPLOYER_LNAME", _
Replace:=wdReplaceAll
End With
Thanks!!!
Find Function In Word - Mix Text And Num
I'm a newbie to the forum. I'm running a new Apple iBook and I have found a word process I like a little better than Word. Problem is, the whole world is on Word, and my chosen word processor will only export to RTF. That's actually not a big deal except that all the footnotes come out at the end of the document with the numbering convention *[footnote number]*.
I'm working on a Word Macro that can take these "end notes" and put them back in as footnotes. Part of the macro will search for, for example, footnote #1 by looking for .text = "*1*".
But I have to create a loop that will capture all of my operations for every footnote. Question: how can I create a loop in my macro that will search for the actual text * but include the number of the loop so I capture all of them. In an ideal world I would simply write:
For j = 1 to 15
Selection.Find.Execute
Selection.Find.ClearFormatting
With Selection.Find
.Text = "*" j "*"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
[then all my operations]
next
But alas that won't compile, of course. Can anyone help me out? I realize this is a dumb question but I'm a rookie at this stuff.
Thanks!
Rich Hoyer
Apple iBook G4
Dell D600 dual boot Win XP & Red Hat 9.0
Find The Style Of A Heading In Word
Hi!
I want to store the style of the last heading (heading 1, heading 2 etc.) before the caret position(insertionpoint) in a variable. I've done this by starting at the top of the document and search down to the caret(Selection.start) and check the styles of the words on the way down. This works, but I think it would be easier and very time saving to start at the caretposition in the text and search upwards in the text and store the first heading I meet. Is this possible to do? I really need help on this one!
here's my code so far:
Dim MyWord As Rang
Dim number As Long
number = 0
'variable to store the number of characters from the beginning of
'the text to the caretposition
Dim number3
number3 = Selection.Start
'Checking ach numbers until I'm at the caretposistion
For Each MyWord In ActiveDocument.Words
number = MyWord.Characters.Count + number
If number >= number2 Then
Exit For
End If
checking the style of the word
select case MyWord.Style
case "header1"
store header1.......
case "header2"
store header2.....
end select
Next MyWord
Find/Replace In Word From Excel
I'm trying to create a macro that can find and replace data in a word document. But this macro is in an excel file. I know how to open a word file within an excel file, but looks like I can't activate it to do the find/replace job. Is there any way to do this? thank you
Lina
Word Automation Find And Replace
I have written some code using fso that searches through files and folders and a macro that find and replace text. But I am not sure how to put the two together. Can anyone help
Code:
Private Sub Document_Open()
Dim strPathToBrowse As String
Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
Dim fsoFiles As Files
Dim fsoFolders As Folders
strPathToBrowse = "a:"
Set fsoFolders = fso.GetFolder(strPathToBrowse).SubFolders
RenderFolders fsoFolders
Set fsoFolder = Nothing
Set fsoFolders = Nothing
Set fso = Nothing
End Sub
'Macro is in a module not sure how to call it up???
Sub Macro1()
'
' Macro1 Macro
'
For Each myfilename In mydir
ChangeFileOpenDirectory _
"C:\"
Documents.Open FileName:="d1.doc", ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto
Selection.Find.ClearFormatting
Selection.Find.Font.Bold = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Bold = True
.Italic = True
End With
With Selection.Find
.Text = "Change This Text"
.Replacement.Text = "New Changed Text"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveDocument.Close
Next myfilename
End Sub
How To Find Word Built-in Commands
Hello,
I'm trying to override some of Word's built-in commands, but can't figure out to which of them some keys are bound to. Specifically, I can't find the command for the Backspace key...
Does anyone know and easy way of identifying which command a given key triggers?
Regards,
Guillermo
Word VBA..Another Find And Copy Issue!
I am really stuck on this one. Being used to excel or access vba, the word find object seems to be a real bugger! I have a plain text file that I need to search on specific values on each line. If the value is found I need to copy the entire row and then paste it into another text file. Return to the original file and continue till EOF. I have tried the EOF function, selection.find and range.find to now avail. The find copies the first record and pastes it into the new document, but never proceeds through. The info I have found on this seems very confusing. Any one care to clear my aching head on this one? My code is below.
Sub Find22()
Dim myStoryRange As Range
On Error GoTo find22_error
SetUpApp
Documents("apclw.txt").Activate
Selection.HomeKey Unit:=wdLine
For Each myStoryRange In ActiveDocument.StoryRanges
With myStoryRange.Find
.Wrap = wdFindContinue
.Execute FindText:="22-"
Selection.GoTo what:=wdGoToLine, which:=wdGoToFirst
End With
If myStoryRange.Find.Found = True Then GoTo foundit
If myStoryRange.Find.Found = False Then GoTo notfound
Next myStoryRange
foundit:
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
Documents("apclw_az.txt").Activate
Selection.HomeKey Unit:=wdLine
Selection.Paste
CloseApp
Exit Sub
notfound:
CloseApp
Exit Sub
find22_error:
ErrorHandler
CloseApp
End Sub
Problem With MS Word VBA : Find-Replace
Hello to All Forum Programmers,
I need your help. I need to automate Microsoft Word 2000 Find & Replace automation. I have written following code and getting error as "String parameter too long". I don't know what to do with this code as I can't truncate the Replacement text.
Here is my code ...
Code:
Set oWord = CreateObject("Word.Application")
If Err.Number > 0 Then
Set oWord = CreateObject("Word.Application")
End If
oWord.Visible = False
oWord.Documents.Open (App.Path & " emplate.doc")
oWord.Selection.Find.ClearFormatting
oWord.Selection.Find.Replacement.ClearFormatting 'This is the error line.
With oWord.Selection.Find
.Text = "##comment##" ' word to search for"
.Replacement.Text = GetComment(sFileData) ' word to replace with
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
oWord.Selection.Find.Execute Replace:=wdReplaceAll 'Do all the replacing now
'Close document
oWord.ActiveDocument.Close
oWord.Quit wdSaveChanges
Though not shown in code above, oWord object is defined as Object and the GetComment function returns the text extracted from a pre-formated file. This Text sometimes is of 3 paragraphs, eash made up of 4 to 9 lines! I can understand if this too much for Word's Replacement method. But if not this way, then how to get this to work?
I have no clue. Please let me know how to overcome this problem. Waiting for your reply ...
Regards,
Ruturaj.
Find Text Then Bold It Via VB6 And Word
I'm trying to programmatically make a phrase bold and underlined within a Word document text that I generate from a VB6 app. Ideally I'd like to do this right as the text is added to the document, but I don't think there's a way to do this since the text I insert comes from the database (I do wonder if it can be done when I'm hardcoding text that goes into a Word document from VB6, this can also be useful to me).
At any rate, once text is inserted into Word from the database, I go to a bookmark, then I'm try to find the first instance of a specific phrase after the bookmark and make it bold & underlined. Is there a way to do this? Here's my snippet that didn't work:
Code:
WordDoc.Bookmarks("blah_blah").Select
With WordDoc.Bookmarks("blah_blah").Range.Find
.Text = "blah"
.Replacement.Text = "blah"
With .Replacement.Text
.Bold = True
.Underline = True
End With
End With
Thanks
~Laz
|