diff --git a/PROMS/LBWordLibrary/LBObjectExtension.cs b/PROMS/LBWordLibrary/LBObjectExtension.cs index ca093c13..d04b1e4e 100644 --- a/PROMS/LBWordLibrary/LBObjectExtension.cs +++ b/PROMS/LBWordLibrary/LBObjectExtension.cs @@ -395,12 +395,37 @@ namespace LBWordLibrary // We now need to calculated the last row of text in the PROMS attachment differently. // We now subtract the TopMargin the Page Setup from the Vertical Position Relative to the Page // this works with older versions of MS Word as well. - float partial = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage) - myRange.PageSetup.TopMargin; + float partial = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage) - GetTopMargin(myRange); // B2019-169 added function to get top margin partial += myRange.Font.Size; retval += partial / 7200; return retval; } } + // B2019-169 + // Would sometimes not return the top margin from Word. We added a Try/Catch and attempt an alternative way doing this, else we log an error and return a zero top margin + public float GetTopMargin (LBRange myRange) + { + try + { + myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToLast, 100); + return myRange.PageSetup.TopMargin; + } + catch + { + try + { + myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToAbsolute, 0); + float tpmar = myRange.PageSetup.TopMargin; + myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToLast, 100); + return tpmar; + } + catch + { + _MyLog.ErrorFormat("Unable to read Top Margin"); + return 0; + } + } + } public string Ascii { get