Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 2nd, 2004, 01:25 PM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Issue w/ IF/FIND statements..

I have placed the attached code into the code window of MS Word's Normal.dot in the Document_open event so that it will run automatically (I highlight all the docs that I want affected by this script and press enter to fire them all off - this method works fine - jsut some background)

The code works, no errors, with the exception of the first part fo the if statement. I tested this on 3 documents.

one that contained the text: LOCATION(S): THERE
one that contained the text: LOCATION(S): HERE
one that contained the text: LOCATION(S): THERE; HERE

The idea is that if it has the word: HERE in it, then write the filename and title to a log file..

after running all three of these test docs through the script, only the one that said: LOCATION(S): THERE; HERE was in the log

my question is, what am i doing wrong that the one that contained the text: LOCATION(S): HERE does not show up in my log?

I WOULD GREATLY APPRECIATE ANY HELP IN THIS!!! :)


Code:
Sub notThere()

    Selection.HomeKey Unit:=wdStory ' just to be safe, start at the top of doc
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader ' view header
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "LOCATION(S):" & vbTab & "HERE"
        If .Execute = True Then
            Call getTitle 'get title and filename and write to log file
            Exit Sub
        Else
            Selection.HomeKey Unit:=wdStory ' just to be safe, start at the top of doc
            ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader ' view header
            Selection.Find.ClearFormatting
            With Selection.Find
                .Text = "LOCATION(S):" & vbTab & "THERE; HERE"
                If .Execute = True Then
                    Call getTitle 'get title and filename and write to log file
                Else
                    ActiveDocument.Close 'if it is neither of these options, kill document
                End If
            End With
        End If
    End With
End Sub
 
Old December 7th, 2004, 11:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

The only thing I can think of is that someone didn't type a TAB between the colon and the word "HERE". Perhaps the person typed one or two spaces after the colon, so you're not finding it.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old December 7th, 2004, 03:35 PM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

bingo - this was the issue - thanks for the reply






Similar Threads
Thread Thread Starter Forum Replies Last Post
if statements brainchild Javascript 2 March 1st, 2007 06:08 AM
Open Word Doc from Access - find, find next save donaldmaloney Access VBA 1 May 25th, 2005 11:09 AM
If, else if statements Joel JSP Basics 0 March 18th, 2004 06:17 PM
Create a find and a find and replace in VB.NET snowy0 VB How-To 0 January 26th, 2004 07:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.