Question about sections

I

iris

Hello everybody!

I need to write a macro that checks if the cursor is in the last section of
the document (regardless of how much sections there are in the document),
if - YES then
check if the layout of the section is portrait
if yes then
msgbox "portrate"
if NO then
change the layout to portrate and delete the section

I have tried and tries and failed...

I hope you will be able to help me

Thank you

Iris
 
G

Greg Maxey

Sub ScratchMacro()
Dim oRng As Word.Range
If Selection.Information(wdActiveEndSectionNumber) =
ActiveDocument.Sections.Count Then
If Selection.Sections(1).PageSetup.Orientation = wdOrientPortrait Then
MsgBox "Portrait"
Set oRng = ActiveDocument.Sections.Last.Range
oRng.MoveStart wdCharacter, -1
oRng.Delete
End If
End If
End Sub
 
I

iris

Hi greg

Thank you for your help!

This cod works great... but I have to problems with it:

1. When the section is delited - the headers and footers of the privious
section is deleted to... I don't want them to be deleted

2. If the cursor is not in the last section - I need a msgbox theat sais:
"you are not in the last section"

Hope you can help me with that to...

Iris
 
G

Greg Maxey

1. When the section is delited - the headers and footers of the privious
section is deleted to... I don't want them to be deleted


Sub ScratchMacro()
Dim i As Long
Dim oRng As Word.Range
If Selection.Information(wdActiveEndSectionNumber) =
ActiveDocument.Sections.Count Then
If Selection.Sections(1).PageSetup.Orientation = wdOrientPortrait Then
MsgBox "Portrait"
With ActiveDocument.Sections.Last
For i = 1 To 3
.Headers(i).LinkToPrevious = False
.Footers(i).LinkToPrevious = False
Next i
Set oRng = .Range
End With
oRng.MoveStart wdCharacter, -1
oRng.Delete
End If
End If
End Sub
2. If the cursor is not in the last section - I need a msgbox theat sais:
"you are not in the last section"


Something tells me that you have yet to try.
 
I

iris

OK... now IM LOST :)


In regard to 1. :

If the section is portrate, You create the message... ans still delete the
sectio....

what I need... and unfortunatly can't figure out is the following:

1. If the section is portrait, give the messege: "portrate" and DON'T delete
the section - Just exit the sub.

2. Check if the section is not the last section of the document... - IF NOT
(if the section is not the last section of the document...) send a message:
"Not the last section" and exit sub

2. If the section is Landscape - CHANGE it into Portrate and then DELETE the
section - WITHOUT deleting the headers and footers of the previous section

I hope now it's clearer... and I realy hope you can help me with that - I'M
GOING NUTS!!!

Thank you so much!!
 
G

Greg Maxey

Sub ScratchMacro()
Dim i As Long
Dim oRng As Word.Range
If Selection.Information(wdActiveEndSectionNumber) = _
ActiveDocument.Sections.Count Then
If Selection.Sections(1).PageSetup.Orientation = wdOrientPortrait Then
MsgBox "Portrait"
Exit Sub
Else
With ActiveDocument.Sections.Last
'If your going to delete it anyway then what difference does it _
make if it is portrait or landscape?
.PageSetup.Orientation = wdOrientPortrait
For i = 1 To 3
.Headers(i).LinkToPrevious = False
.Footers(i).LinkToPrevious = False
Next i
Set oRng = .Range
End With
oRng.MoveStart wdCharacter, -1
oRng.Delete
End If
Else
MsgBox "Not the last section."
End If
End Sub
 
I

iris

Hi Greg,

Another subject completly...

I red your article about listboxes and learned a lot from them. But, I
encountered a problem wich I can't seem to bit... I really hope you can help
me with it... I'm desperate!!!!

I have a userform1 in word that feeds from an access database.

In that form I have :
textbox1 - in which i write the string I need to search
optionbutton1 - in which I choose the column I need to search the string in
the database
comandbutton1 - to execute the search
listbox1 - in which I need the list of the results to appear

The code I wrote execute the search sucssessfully but I don't know how to
build the array for all the resualts.... I only get one resault at a time and
eventually - only the last resault appears in the list box.

I need all the resualts to appear in the listbox.

I used some of your code in this sub....

This is the code I wrote:

Private Sub CommandButton1_Click()

Dim dbDatabase As Database
Dim rse As Recordset
Dim rsi As Recordset
Dim e As Integer
Dim i As Integer
Dim d As Boolean

Set dbDatabase = OpenDatabase("C:\nihul.mdb")
Set rse = dbDatabase.OpenRecordset("SELECT * FROM expressions ;",
dbOpenSnapshot)

Dim myActiveRecord As Recordset
Dim x As Long
x = 0


Dim eStr As String
Dim answer As String
d = False
i = 0
e = 0

If TextBox1.Text = "" Then
MsgBox "enter a search value", vbOKOnly + vbExclamation
d = True
Else
If OptionButton1.Value = False Then
MsgBox "choose a search category", vbOKOnly + vbExclamation
d = True
Else
If OptionButton1.Value = True Then

ListBox1.Clear

With rse
Do Until .EOF
eStr = ![heb]
If InStr(![heb], TextBox1.Text) > 0 Then
d = True
i = i + 1
TextBox2.Text = ![heb]
ListBox1.AddItem

********HERE i USED yOUR CODE*******

Set dbDatabase = OpenDatabase("C:\nihul.mdb")

Set myActiveRecord = myDataBase.OpenRecordset("SELECT * FROM expressions
WHERE heb = '" & TextBox2.Text & "'", dbOpenForwardOnly)

ListBox1.ColumnCount = myActiveRecord.Fields.Count

Do While Not myActiveRecord.EOF
ListBox1.AddItem
ListBox1.ColumnCount = 7
ListBox1.BoundColumn = 7
ListBox1.ColumnWidths = "4 in;1 in;1 in;1 in;1 in;1 in;0 in;"
ListBox1.List(x, 6) = myActiveRecord.Fields("hebrt")
ListBox1.List(x, 5) = myActiveRecord.Fields("heb")
ListBox1.List(x, 4) = myActiveRecord.Fields("engRT")
ListBox1.List(x, 3) = myActiveRecord.Fields("eng")
ListBox1.List(x, 2) = myActiveRecord.Fields("employeeName")
ListBox1.List(x, 1) = myActiveRecord.Fields("lastUpdate")
ListBox1.List(x, 0) = myActiveRecord.Fields("hebshort")
x = x + x

myActiveRecord.MoveNext
Loop

myActiveRecord.Close
myDataBase.Close
Set myActiveRecord = Nothing
Set myDataBase = Nothing

answer = MsgBox("R U sure?" & TextBox1.Text & ". ,
vbQuestion)
If answer = vbNo Then
Exit Sub
Else
End If
End If
.MoveNext
e = e + 1
Loop
End With
End If
End If
End If

rse.Close
dbDatabase.Close
If d = False Then
MsgBox "no resaults are found", vbOKOnly + vbExclamation
End If

End Sub
 
I

iris

Hi Greg

I tried to contact you via your site but the mail returned.

I am braking my head with this problem... and the more Im looking at eat -
the more I am convinced that I am missing something with building the array
that populates the listbox...

It will be great if you could take a look at this... Im sure that it needs
another set of eyes and a fresh look...

Thank you in advance

Iris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top