Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #14  
Old 09-19-2017, 11:56 AM
slaycock slaycock is offline Find This Or That On Line Six of Word Document Windows 7 64bit Find This Or That On Line Six of Word Document Office 2013
Expert
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

There are a number of mistakes

i would recommend you google

vba if statement
vba declaring variables
vba set statement

ActiveDocument.Paragraphs(6).Range

Range is a property that returns a range object

it can be used in two ways.

1. to access further properties so you can set a value

e.g

Code:
ActiveDocument.Paragraphs(6).Range.Text="Hello world"
2. assign the range to another variable

Code:
set myRange = ActiveDocument.Paragraphs(6).Range.Text="Hello world"
means that myRange points to the range of paragraph(6) of the active document.

Range is an 'object' which is why you have to use set rather than just

Code:
myRange = ActiveDocument.Paragraphs(6).Range.Text="Hello world"
as in

Code:
myInteger = 4
So at the moment you code does not use the value returned by the statement

Code:
ActiveDocument.Paragraphs(6).Range

The variable myRange is declared but nothing is ever assigned to it.

The if statement exists in two forms (three if you want to b pedantic)

1. Use on a single line

If <condition> then <do something

2 Use over a number of lines

if <condition then
<do something>
ElseIf <condition> then
<do something else>
Else
< do stuff not captured by the above conditions>
End if

The else and elseif are optional statements. Else can only occur once but elseif can occur as many times as you want.

Your code misses out the mandatory Then and does not close with the End if.

The third version is called the immediate if and is a shorthand versions of

If <condition> then
do one statement
Else
do one statement
end if

and takes the form

<value> =Iif(<condition>, true statement, false statement)


Its very commonly used when you need to set a variable to one of two values depending on something that happened elsewhere.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find This Or That On Line Six of Word Document Black line that is in word document that won't go away ! seyzna Word 7 05-22-2023 10:57 AM
Find This Or That On Line Six of Word Document Won't find Word document wblock@cnu.edu Word 4 08-23-2017 06:11 PM
Find This Or That On Line Six of Word Document Cannot find my word document - saved to usb mssodium1219 Word 3 04-01-2015 04:24 AM
Find This Or That On Line Six of Word Document Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Word 2003 cuts the last line of my document off wordboy9317 Word 0 10-12-2009 08:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft