inserting section break - changing to landscape and then back

B

bryan

I have inserted documents into templates with macros and have come across a
new one.
The doc I want to insert is in landscape.
How can I change the orientation and then change back after inserting the
file.
Here is my macro:
Sub HOCheck3()
If ActiveDocument.FormFields("HOC3").CheckBox.Value = True Then

If ILchk = 0 Then

Dim myDoc As Document
Dim docrange As Range

Set myDoc = ActiveDocument
myDoc.Unprotect
Set docrange = myDoc.Range

With docrange
.Collapse wdCollapseEnd
.InsertBreak wdSectionBreakNextPage

.Collapse wdCollapseEnd

.InsertFile "U:\HO Inventory List.doc"
End With
myDoc.Protect wdAllowOnlyFormFields, NoReset


If strFW <> "" Then
Dim bmRange As Range
Set bmRange = ActiveDocument.Bookmarks("ILFW").Range
ActiveDocument.AttachedTemplate.AutoTextEntries(strFW).Insert
WHERE:=bmRange, RichText:=True
ActiveDocument.Bookmarks.Add _
Name:="ILFW", _
Range:=bmRange
End If
'
With ActiveDocument
ActiveDocument.Unprotect
.FormFields("HideP1").Range.Paragraphs(1).Range.Font.Hidden = False
.FormFields("HOC3").Range.Paragraphs(1).Range.Font.Hidden = False
ActiveWindow.View.ShowHiddenText = True
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset
End With

ILchk = ILchk + 1
Call UpdRef
Else
End If
End If

End Sub

Thanks,
Bryan
 
J

Jean-Guy Marcil

bryan said:
I have inserted documents into templates with macros and have come across a
new one.
The doc I want to insert is in landscape.
How can I change the orientation and then change back after inserting the
file.
Here is my macro:
Sub HOCheck3()
If ActiveDocument.FormFields("HOC3").CheckBox.Value = True Then

If ILchk = 0 Then

Dim myDoc As Document
Dim docrange As Range

Set myDoc = ActiveDocument
myDoc.Unprotect
Set docrange = myDoc.Range

With docrange
.Collapse wdCollapseEnd
.InsertBreak wdSectionBreakNextPage

.Collapse wdCollapseEnd

.InsertFile "U:\HO Inventory List.doc"
End With
myDoc.Protect wdAllowOnlyFormFields, NoReset


If strFW <> "" Then
Dim bmRange As Range
Set bmRange = ActiveDocument.Bookmarks("ILFW").Range
ActiveDocument.AttachedTemplate.AutoTextEntries(strFW).Insert
WHERE:=bmRange, RichText:=True
ActiveDocument.Bookmarks.Add _
Name:="ILFW", _
Range:=bmRange
End If
'
With ActiveDocument
ActiveDocument.Unprotect
.FormFields("HideP1").Range.Paragraphs(1).Range.Font.Hidden = False
.FormFields("HOC3").Range.Paragraphs(1).Range.Font.Hidden = False
ActiveWindow.View.ShowHiddenText = True
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset
End With

ILchk = ILchk + 1
Call UpdRef
Else
End If
End If

if you are inserting the file at the end of the active document, insert a
section break before inserting the file. If you know the file to insert is
landscape, change the last section to landscape. Insert the file. Then, if
you need to continue with the same document, add another section break at the
end and then change the last section to portrait.

If you are inserting the file in the middle of a document, insert 2 section
breaks separated by a paragraph mark. Make that inserted section landscape.


If you want to check whether the file to insert is landscape or not, open it
first, check the orientation, close it, then code appropriately when
inserting it.
 
B

bryan

I am a novice when it comes to this one so I am not sure how to code this,
let alone where to insert into my code.

I would greatly appreciate as much help as possible. This landscape file
could be inserted amongst other portrait files, so I would need to set to
landscape and back to portrait.

Thanks in advance,
Bryan
 
J

Jean-Guy Marcil

bryan said:
I am a novice when it comes to this one so I am not sure how to code this,
let alone where to insert into my code.

I would greatly appreciate as much help as possible. This landscape file
could be inserted amongst other portrait files, so I would need to set to
landscape and back to portrait.

Just be warned that this can get hairy in no time...

At its most basic, you could use something like this:

Dim rgeFile As Range

Set rgeFile = Selection.Range

With rgeFile
.Collapse wdCollapseEnd
.InsertBreak wdSectionBreakNextPage
.InsertParagraphAfter
.Collapse wdCollapseEnd
.InsertBreak wdSectionBreakNextPage
.Move wdParagraph, -2
'Insert file here
.InsertFile...
End With


If you do not want the extra ¶ between the two section breaks prior to
inserting the file:

Dim rgeFile As Range

Set rgeFile = Selection.Range

With rgeFile
.Collapse wdCollapseEnd
.InsertBreak wdSectionBreakNextPage
.InsertBreak wdSectionBreakNextPage
.Move wdParagraph, -1
'Insert file here
.InsertFile...
End With


Here is some code you might need to determine what is going on at the cursor
location prior to inserting the new file:

To check if cursor is in last section:
If Selection.Sections(1).Index = ActiveDocument.Sections.Count Then

To check if cursor at end of file:
Selection.Collapse wdCollapseEnd
If Selection.Range.End + 1 = ActiveDocument.Range.End

("+1" because the end of the document is the last ¶ in the document, which
will not be selected once we collpase the selection.)

Etc.
 
B

bryan

I got it from looking at other forum entries.
Here's what I am doing:
Dim myDoc As Document
Dim docrange As Range


Set myDoc = ActiveDocument
myDoc.Unprotect
Set docrange = myDoc.Range

With docrange
.Collapse wdCollapseEnd
.InsertBreak wdSectionBreakNextPage
.PageSetup.Orientation = wdOrientLandscape
.PageSetup.PageHeight = InchesToPoints(9.2)
.Collapse wdCollapseEnd

.InsertFile "U:\Claims Templates\4968\HO\HO Inventory List.doc"
End With
myDoc.Protect wdAllowOnlyFormFields, NoReset

'In the other checkboxes I set to portrait.

Bryan
 

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