C# Snippets
Page_InsertLandscape
Public Sub Page_LandscapeInsert(ByRef objDocument As Word.Document, _
ByVal sDocumentType As String, _
ByVal sDocumentTemplate_Code As String)
Dim objCurrentPageFit As Word.WdPageFit
Dim iCurrentViewPercentage As Integer
Dim objSection As Word.Section
Dim objSectionPrevious As Word.Section
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
objCurrentPageFit = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit
iCurrentViewPercentage = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = Word.WdPageFit.wdPageFitFullPage
If modWordObjectModel.Section_CanBeChanged(objDocument, sDocumentTemplate_Code) = False Then
Exit Sub
Else
objSection = gApplicationWord.Selection.Sections(1)
gApplicationWord.Selection.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
objSectionPrevious = gApplicationWord.Selection.Sections(1)
gApplicationWord.Selection.MoveDown(Unit:=Word.WdUnits.wdLine, Count:=1)
If Not (objSectionPrevious.Index < objSection.Index) Then
gApplicationWord.Selection.InsertBreak(Type:=Word.WdBreakType.wdSectionBreakNextPage)
With gApplicationWord.Selection
.TypeParagraph()
.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
.Style = objDocument.Styles("B-Section Heading")
.TypeText(Text:="New Section")
.TypeParagraph()
.Style = objDocument.Styles("B-Heading 2. Full Width")
.TypeText(Text:="Style: B-Heading 2. Full Width")
.InsertBreak(Type:=Word.WdBreakType.wdSectionBreakNextPage)
.Delete()
.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
Call modWordObjectModel.Page_CheckOrientation(objDocument, sDocumentType, sDocumentTemplate_Code)
End With
Else
With gApplicationWord.Selection
.TypeParagraph()
.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
.Style = objDocument.Styles("B-Section Heading")
.TypeText(Text:="New Section")
.TypeParagraph()
'.MoveLeft Unit:=wdCharacter, Count:=1
'.TypeParagraph
.Style = objDocument.Styles("B-Heading 2. Full Width")
.TypeText(Text:="Style: B-Heading 2. Full Width")
.InsertBreak(Type:=Word.WdBreakType.wdSectionBreakNextPage)
.Delete()
.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
Call modWordObjectModel.Page_CheckOrientation(objDocument, sDocumentType, sDocumentTemplate_Code)
End With
End If
End If
Call modWordObjectModel.Page_LandscapeFormat(objDocument, sDocumentType, sDocumentTemplate_Code)
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = objCurrentPageFit
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage = iCurrentViewPercentage
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"insert a landscape page at this point in the document." & _
System.Environment.NewLine & _
System.Environment.NewLine & _
"Please check the formatting in this section.")
End Try
End Sub
Page_InsertPortrait
public void Page_PortraitInsert(ref Word.Document objDocument, string sDocumentType, string sDocumentTemplate_Code)
{
Word.WdPageFit objCurrentPageFit;
int iCurrentViewPercentage;
Word.Section objTargetSection;
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;
objCurrentPageFit = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit;
iCurrentViewPercentage = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage;
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = Word.WdPageFit.wdPageFitFullPage;
if (modWordObjectModel.Section_CanBeChanged(objDocument, sDocumentTemplate_Code) == false)
return;
else
{
var withBlock = gApplicationWord.Selection;
withBlock.Collapse(Word.WdCollapseDirection.wdCollapseStart);
withBlock.InsertBreak(Type: Word.WdBreakType.wdSectionBreakNextPage);
withBlock.Style = objDocument.Styles("B-Section Heading");
withBlock.TypeText(Text: "Section Header");
withBlock.TypeParagraph();
withBlock.Style = objDocument.Styles("B-Heading 1");
withBlock.TypeText(Text: "Heading 1");
objTargetSection = gApplicationWord.Selection.Sections(1);
withBlock.TypeParagraph();
withBlock.TypeParagraph();
withBlock.InsertBreak(Type: Word.WdBreakType.wdSectionBreakNextPage);
modWordObjectModel.Page_CheckOrientation(objDocument, sDocumentType, sDocumentTemplate_Code);
}
modWordObjectModel.Page_PortraitFormat(objDocument, sDocumentType, sDocumentTemplate_Code, objTargetSection);
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = objCurrentPageFit;
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage = iCurrentViewPercentage;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex, "insert a portrait page at this point in the document." + System.Environment.NewLine + System.Environment.NewLine + "Please check the formatting in this section.");
}
}
Public Sub Page_PortraitInsert(ByRef objDocument As Word.Document, _
ByVal sDocumentType As String, _
ByVal sDocumentTemplate_Code As String)
Dim objCurrentPageFit As Word.WdPageFit
Dim iCurrentViewPercentage As Integer
Dim objTargetSection As Word.Section
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
objCurrentPageFit = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit
iCurrentViewPercentage = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = Word.WdPageFit.wdPageFitFullPage
If modWordObjectModel.Section_CanBeChanged(objDocument, sDocumentTemplate_Code) = False Then
Exit Sub
Else
With gApplicationWord.Selection
.Collapse(Word.WdCollapseDirection.wdCollapseStart)
.InsertBreak(Type:=Word.WdBreakType.wdSectionBreakNextPage)
.Style = objDocument.Styles("B-Section Heading")
.TypeText(Text:="Section Header")
.TypeParagraph()
.Style = objDocument.Styles("B-Heading 1")
.TypeText(Text:="Heading 1")
objTargetSection = gApplicationWord.Selection.Sections(1)
.TypeParagraph()
.TypeParagraph()
.InsertBreak(Type:=Word.WdBreakType.wdSectionBreakNextPage)
Call modWordObjectModel.Page_CheckOrientation(objDocument, sDocumentType, sDocumentTemplate_Code)
End With
End If
Call modWordObjectModel.Page_PortraitFormat(objDocument, sDocumentType, sDocumentTemplate_Code, objTargetSection)
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = objCurrentPageFit
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage = iCurrentViewPercentage
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"insert a portrait page at this point in the document." & _
System.Environment.NewLine & _
System.Environment.NewLine & _
"Please check the formatting in this section.")
End Try
End Sub
Page_IntentionallyBlankInsert
public void Page_IntentionallyBlankInsert(ref Word.Document objDocument, string sDocumentTemplate_Code)
{
Word.WdPageFit objCurrentPageFit;
int iCurrentViewPercentage;
Word.Section objSection;
Word.Section objSectionPrevious;
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;
objCurrentPageFit = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit;
iCurrentViewPercentage = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage;
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = Word.WdPageFit.wdPageFitFullPage;
if ((modWordObjectModel.Section_CanBeChanged(objDocument, sDocumentTemplate_Code) == false))
return;
else
{
objSection = gApplicationWord.Selection.Sections(1);
if (objSection.PageSetup.Orientation == Word.WdOrientation.wdOrientLandscape)
{
modMessages.Message_General_OperationNotAllowedInLandscape();
return;
}
gApplicationWord.Selection.MoveUp(Unit: Word.WdUnits.wdLine, Count: 1);
objSectionPrevious = gApplicationWord.Selection.Sections(1);
gApplicationWord.Selection.MoveDown(Unit: Word.WdUnits.wdLine, Count: 1);
if (!(objSectionPrevious.Index < objSection.Index))
{
{
var withBlock = gApplicationWord.Selection;
withBlock.TypeParagraph();
withBlock.MoveUp(Unit: Word.WdUnits.wdLine, Count: 1);
withBlock.Style = objDocument.Styles("B-TextPageLeftyBlank");
withBlock.TypeText(Text: "This page is intentionally left blank");
}
}
else
{
var withBlock = gApplicationWord.Selection;
withBlock.TypeParagraph();
withBlock.MoveUp(Unit: Word.WdUnits.wdLine, Count: 1);
withBlock.Style = objDocument.Styles("B-TextPageLeftyBlank");
withBlock.TypeText(Text: "This page is intentionally left blank");
}
}
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = objCurrentPageFit;
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage = iCurrentViewPercentage;
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex, "insert an intentionally blank page." + System.Environment.NewLine + System.Environment.NewLine + "Please check the formatting in this section.");
}
}
Public Sub Page_IntentionallyBlankInsert(ByRef objDocument As Word.Document, _
ByVal sDocumentTemplate_Code As String)
Dim objCurrentPageFit As Word.WdPageFit
Dim iCurrentViewPercentage As Integer
Dim objSection As Word.Section
Dim objSectionPrevious As Word.Section
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
objCurrentPageFit = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit
iCurrentViewPercentage = gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = Word.WdPageFit.wdPageFitFullPage
If (modWordObjectModel.Section_CanBeChanged(objDocument, sDocumentTemplate_Code) = False) Then
Exit Sub
Else
objSection = gApplicationWord.Selection.Sections(1)
If objSection.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape Then
Call modMessages.Message_General_OperationNotAllowedInLandscape()
Exit Sub
End If
gApplicationWord.Selection.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
objSectionPrevious = gApplicationWord.Selection.Sections(1)
gApplicationWord.Selection.MoveDown(Unit:=Word.WdUnits.wdLine, Count:=1)
If Not (objSectionPrevious.Index < objSection.Index) Then
With gApplicationWord.Selection
.TypeParagraph()
.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
.Style = objDocument.Styles("B-TextPageLeftyBlank")
.TypeText(Text:="This page is intentionally left blank")
'.InsertBreak Type:=wdSectionBreakNextPage
'.Delete
'.MoveUp Unit:=wdLine, Count:=1
'.ParagraphFormat.Alignment = wdAlignParagraphCenter
'.PageSetup.VerticalAlignment = wdAlignVerticalCenter
'Call CheckOrientation
End With
Else
With gApplicationWord.Selection
.TypeParagraph()
.MoveUp(Unit:=Word.WdUnits.wdLine, Count:=1)
.Style = objDocument.Styles("B-TextPageLeftyBlank")
.TypeText(Text:="This page is intentionally left blank")
End With
End If
End If
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.PageFit = objCurrentPageFit
gApplicationWord.ActiveWindow.ActivePane.View.Zoom.Percentage = iCurrentViewPercentage
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"insert an intentionally blank page." & _
System.Environment.NewLine & _
System.Environment.NewLine & _
"Please check the formatting in this section.")
End Try
End Sub
Page_LandscapeFormat
public void Page_LandscapeFormat(ref Word.Document objDocument, string sDocumentType, string sDocumentTemplate_Code, Word.Section oTargetSection = null/* TODO Change to default(_) if this is not a reference type */, bool SkipTableStretch = false)
{
docSectionMargins oMargins;
Word.Section oNextSection;
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;
if (oTargetSection == null)
oTargetSection = gApplicationWord.Selection.Sections(1);
else
oTargetSection = oTargetSection;
if (modWordObjectModel.Section_CanBeChanged(objDocument, sDocumentTemplate_Code) == false)
return;
else
{
{
var withBlock = oTargetSection;
{
var withBlock1 = withBlock.PageSetup;
oMargins.TopMargin = withBlock1.TopMargin;
oMargins.BottomMargin = withBlock1.BottomMargin;
oMargins.LeftMargin = withBlock1.LeftMargin;
oMargins.RightMargin = withBlock1.RightMargin;
oMargins.Footer = withBlock1.FooterDistance;
oMargins.Header = withBlock1.HeaderDistance;
}
if (objDocument.Sections.Count > oTargetSection.Index)
{
oNextSection = objDocument.Sections(oTargetSection.Index + 1);
{
var withBlock1 = oNextSection;
withBlock1.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = false;
}
}
withBlock.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = false;
// .Footers(Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).LinkToPrevious = False
// .Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).LinkToPrevious = False
withBlock.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape;
// Application.DoEvents()
{
var withBlock1 = withBlock.PageSetup;
withBlock1.TopMargin = oMargins.TopMargin;
withBlock1.BottomMargin = oMargins.BottomMargin;
withBlock1.LeftMargin = oMargins.LeftMargin;
withBlock1.RightMargin = oMargins.RightMargin;
withBlock1.FooterDistance = oMargins.Footer;
withBlock1.HeaderDistance = oMargins.Header;
}
// Application.DoEvents()
{
var withBlock1 = withBlock.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.ParagraphFormat;
withBlock1.TabStops.ClearAll();
withBlock1.TabStops.Add(Position: getTabstop(oTargetSection), Alignment: Word.WdTabAlignment.wdAlignTabRight, Leader: Word.WdTabLeader.wdTabLeaderSpaces);
}
}
if (SkipTableStretch == false)
modWordTables.Table_Stretcher(oTargetSection);
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex, "convert the selected section to landscape." + System.Environment.NewLine + System.Environment.NewLine + "Please check the formatting in this section.");
}
}
Public Sub Page_LandscapeFormat(ByRef objDocument As Word.Document, _
ByVal sDocumentType As String, _
ByVal sDocumentTemplate_Code As String, _
Optional ByVal oTargetSection As Word.Section = Nothing, _
Optional ByVal SkipTableStretch As Boolean = False)
Dim oMargins As docSectionMargins
Dim oNextSection As Word.Section
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If oTargetSection Is Nothing Then
oTargetSection = gApplicationWord.Selection.Sections(1)
Else
oTargetSection = oTargetSection
End If
If modWordObjectModel.Section_CanBeChanged(objDocument, sDocumentTemplate_Code) = False Then
Exit Sub
Else
With oTargetSection
With .PageSetup
oMargins.TopMargin = .TopMargin
oMargins.BottomMargin = .BottomMargin
oMargins.LeftMargin = .LeftMargin
oMargins.RightMargin = .RightMargin
oMargins.Footer = .FooterDistance
oMargins.Header = .HeaderDistance
End With
If objDocument.Sections.Count > oTargetSection.Index Then
oNextSection = objDocument.Sections(oTargetSection.Index + 1)
With oNextSection
.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = False
'.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).LinkToPrevious = False
'.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).LinkToPrevious = False
End With
End If
.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = False
'.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).LinkToPrevious = False
'.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).LinkToPrevious = False
.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape
'Application.DoEvents()
With .PageSetup
.TopMargin = oMargins.TopMargin
.BottomMargin = oMargins.BottomMargin
.LeftMargin = oMargins.LeftMargin
.RightMargin = oMargins.RightMargin
.FooterDistance = oMargins.Footer
.HeaderDistance = oMargins.Header
End With
'Application.DoEvents()
With .Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.ParagraphFormat
.TabStops.ClearAll()
.TabStops.Add(Position:=getTabstop(oTargetSection), _
Alignment:=Word.WdTabAlignment.wdAlignTabRight, _
Leader:=Word.WdTabLeader.wdTabLeaderSpaces)
End With
'Application.DoEvents()
End With
If SkipTableStretch = False Then
Call modWordTables.Table_Stretcher(oTargetSection)
End If
End If
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"convert the selected section to landscape." & _
System.Environment.NewLine & _
System.Environment.NewLine & _
"Please check the formatting in this section.")
End Try
End Sub
Page_OrientationCheck
public void Page_OrientationCheck(ref Word.Document objDocument, string sDocumentType, string sDocumentTemplate_Code, Word.Section oTargetSection = null/* TODO Change to default(_) if this is not a reference type */, bool SkipTableStretch = false)
{
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;
if (gApplicationWord.Selection.PageSetup.Orientation == Word.WdOrientation.wdOrientLandscape)
modWordObjectModel.Page_LandscapeFormat(objDocument, sDocumentType, sDocumentTemplate_Code, oTargetSection, SkipTableStretch);
else
modWordObjectModel.Page_PortraitFormat(objDocument, sDocumentType, sDocumentTemplate_Code, oTargetSection, SkipTableStretch);
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex);
}
}
Public Sub Page_OrientationCheck(ByRef objDocument As Word.Document, _
ByVal sDocumentType As String, _
ByVal sDocumentTemplate_Code As String, _
Optional ByVal oTargetSection As Word.Section = Nothing, _
Optional ByVal SkipTableStretch As Boolean = False)
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If gApplicationWord.Selection.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape Then
Call modWordObjectModel.Page_LandscapeFormat(objDocument, _
sDocumentType, _
sDocumentTemplate_Code, _
oTargetSection, _
SkipTableStretch)
Else
Call modWordObjectModel.Page_PortraitFormat(objDocument, _
sDocumentType, _
sDocumentTemplate_Code, _
oTargetSection, _
SkipTableStretch)
End If
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex)
End Try
End Sub
Page_PortraitFormat
public void Page_PortraitFormat(ref Word.Document objDocument, string sDocumentType, string sDocumentTemplate_Code, Word.Section oTargetSection = null/* TODO Change to default(_) if this is not a reference type */, bool SkipTableStretch = false)
{
docSectionMargins oMargins;
Word.Section oNextSection;
try
{
Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod().Name + " start");
if (My.Settings.ERROR_OCCURRED == true)
return;
if (oTargetSection == null)
oTargetSection = gApplicationWord.Selection.Sections(1);
else
oTargetSection = oTargetSection;
if (modWordObjectModel.Section_CanBeChanged(objDocument, sDocumentTemplate_Code) == false)
return;
else
{
{
var withBlock = oTargetSection;
{
var withBlock1 = withBlock.PageSetup;
oMargins.TopMargin = withBlock1.TopMargin;
oMargins.BottomMargin = withBlock1.BottomMargin;
oMargins.LeftMargin = withBlock1.LeftMargin;
oMargins.RightMargin = withBlock1.RightMargin;
oMargins.Footer = withBlock1.FooterDistance;
oMargins.Header = withBlock1.HeaderDistance;
}
oNextSection = objDocument.Sections(oTargetSection.Index + 1);
{
var withBlock1 = oNextSection;
withBlock1.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = false;
}
withBlock.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = false;
// .Footers(Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).LinkToPrevious = False
// .Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).LinkToPrevious = False
withBlock.PageSetup.Orientation = Word.WdOrientation.wdOrientPortrait;
// Application.DoEvents()
{
var withBlock1 = withBlock.PageSetup;
withBlock1.TopMargin = oMargins.TopMargin;
withBlock1.BottomMargin = oMargins.BottomMargin;
withBlock1.LeftMargin = oMargins.LeftMargin;
withBlock1.RightMargin = oMargins.RightMargin;
withBlock1.HeaderDistance = oMargins.Header;
withBlock1.FooterDistance = oMargins.Footer;
}
// Application.DoEvents()
{
var withBlock1 = withBlock.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.ParagraphFormat;
withBlock1.TabStops.ClearAll();
withBlock1.TabStops.Add(Position: getTabstop(oTargetSection), Alignment: Word.WdTabAlignment.wdAlignTabRight, Leader: Word.WdTabLeader.wdTabLeaderSpaces);
}
}
if (SkipTableStretch == false)
modWordTables.Table_Stretcher(oTargetSection);
}
}
catch (Exception ex)
{
modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod(), null/* TODO Change to default(_) if this is not a reference type */, ex, "convert the selected section to portrait." + System.Environment.NewLine + System.Environment.NewLine + "Please check the formatting in this section.");
}
}
Public Sub Page_PortraitFormat(ByRef objDocument As Word.Document, _
ByVal sDocumentType As String, _
ByVal sDocumentTemplate_Code As String, _
Optional ByVal oTargetSection As Word.Section = Nothing, _
Optional ByVal SkipTableStretch As Boolean = False)
Dim oMargins As docSectionMargins
Dim oNextSection As Word.Section
Try
Call Tracer_Add2("SUBROUTINE", System.Reflection.MethodBase.GetCurrentMethod.Name & " start")
If My.Settings.ERROR_OCCURRED = True Then Exit Sub
If oTargetSection Is Nothing Then
oTargetSection = gApplicationWord.Selection.Sections(1)
Else
oTargetSection = oTargetSection
End If
If modWordObjectModel.Section_CanBeChanged(objDocument, sDocumentTemplate_Code) = False Then
Exit Sub
Else
With oTargetSection
With .PageSetup
oMargins.TopMargin = .TopMargin
oMargins.BottomMargin = .BottomMargin
oMargins.LeftMargin = .LeftMargin
oMargins.RightMargin = .RightMargin
oMargins.Footer = .FooterDistance
oMargins.Header = .HeaderDistance
End With
oNextSection = objDocument.Sections(oTargetSection.Index + 1)
With oNextSection
.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = False
'.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).LinkToPrevious = False
'.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).LinkToPrevious = False
End With
.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).LinkToPrevious = False
'.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages).LinkToPrevious = False
'.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).LinkToPrevious = False
.PageSetup.Orientation = Word.WdOrientation.wdOrientPortrait
'Application.DoEvents()
With .PageSetup
.TopMargin = oMargins.TopMargin
.BottomMargin = oMargins.BottomMargin
.LeftMargin = oMargins.LeftMargin
.RightMargin = oMargins.RightMargin
.HeaderDistance = oMargins.Header
.FooterDistance = oMargins.Footer
End With
'Application.DoEvents()
With .Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.ParagraphFormat
.TabStops.ClearAll()
.TabStops.Add(Position:=getTabstop(oTargetSection), _
Alignment:=Word.WdTabAlignment.wdAlignTabRight, _
Leader:=Word.WdTabLeader.wdTabLeaderSpaces)
End With
'Application.DoEvents()
End With
If SkipTableStretch = False Then
Call modWordTables.Table_Stretcher(oTargetSection)
End If
End If
Catch ex As System.Exception
Call modMessages.Exception(System.Reflection.MethodBase.GetCurrentMethod, Nothing, ex, _
"convert the selected section to portrait." & _
System.Environment.NewLine & _
System.Environment.NewLine & _
"Please check the formatting in this section.")
End Try
End Sub
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited Top