kokapellie1
New Member
- Joined
- May 24, 2019
- Messages
- 4
Hi All,
I normally would not come here, but sadly am now at the deadline and running this as it is does not work. I am trying to get this to auto run on open or just click the Get Report button once to run all three reports f possible.
Any help would be greatly appreciated!!
I normally would not come here, but sadly am now at the deadline and running this as it is does not work. I am trying to get this to auto run on open or just click the Get Report button once to run all three reports f possible.
Code:
[Private Sub CboReportName_Change()
End Sub
Private Sub Document_Open()
CboReportName.AddItem "Report E"
CboReportName.AddItem "Report F"
CboReportName.AddItem "Report G"
End Sub
Private Sub GetReport_Click()
Dim rgePages As Range
Dim oRng As Word.Range
SavePath = "[URL="file://\\nfpgshare-1.edwardjones.com\export\insurance_annuity_operations\Insurance_Operations\Internal_Operational_Reports\Insurance_Operations_Team\Daily_Transmittals"]XXXXXXX\Daily_Transmittals[/URL]"
'SavePath = "C:\Temp\Mark"
Application.ScreenUpdating = False
Select Case CboReportName
Case "Report E"
ReportToOpen = "INS050E.txt"
ReportTrailer = "Life"
Case "Report F"
ReportToOpen = "INS050F.txt"
ReportTrailer = "Disability"
Case "Report G"
ReportToOpen = "INS050G.txt"
ReportTrailer = "LTC"
End Select
Documents.Open FileName:="XXXXXXXX" & ReportToOpen
'Documents.Open FileName:="C:\Temp\Mark" & ReportToOpen
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.92)
.BottomMargin = InchesToPoints(0.92)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(11)
.PageHeight = InchesToPoints(8.5)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
.LayoutMode = wdLayoutModeDefault
End With
Selection.WholeStory
Selection.Font.Size = 8
Selection.MoveUp unit:=wdLine, Count:=1
'insert breaks 5/25/2018
Selection.EndKey unit:=wdStory
With ActiveDocument.Content.Find
Do While .Execute(FindText:="1RUN", Forward:=False, _
Format:=True) = True
With .Parent
.Select
.StartOf unit:=wdParagraph
.Collapse Direction:=wdCollapseEnd
.InsertBreak (wdPageBreak)
'Selection.MoveDown unit:=wdpage, Count:=1
End With
Loop
End With
'*****************************
ActiveDocument.Repaginate
j = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
For i = j To 1 Step -1
NotEmpty = True
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=CStr(i)
Selection.GoTo What:=wdGoToBookmark, Name:="\page"
If Selection.Characters.Count < 3 Then
NotEmpty = False
For Each c In Selection.Characters
If Asc(c) > 13 Then
''Possibly not empty
NotEmpty = True
End If
Next
End If
If NotEmpty = False Then
Selection.Delete
End If
Next
'*************************************
'highlight DEEBIT: Y
'go to beginning
Selection.HomeKey unit:=wdStory
With ActiveDocument.Content.Find
.ClearFormatting
Do While .Execute(FindText:="DEBIT: Y", Forward:=True, _
Format:=True) = True
With .Parent
.HighlightColorIndex = wdYellow
End With
Loop
End With
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
'remove empty lines from the beginning of the report
Do
Selection.EndKey unit:=wdLine, Extend:=wdExtend
If Len(Selection) > 2 Then Exit Do
Selection.Delete
Loop
'remove end of report lines
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = ">>"
While .Execute
oRng.Paragraphs(1).Range.Delete
Wend
End With
ActiveDocument.Repaginate
TotalPages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.MoveDown unit:=wdLine, Count:=3
Selection.MoveRight unit:=wdCharacter, Count:=40, Extend:=wdExtend
StartPage = Selection.Information(wdActiveEndPageNumber)
Vendor1 = Trim(Selection.Text)
For i = 1 To TotalPages
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=i
'verify the first word is RUN otherwise goto next page
Selection.MoveRight unit:=wdWord, Count:=1, Extend:=wdExtend
PageVerify = Selection.Text
Selection.MoveLeft unit:=wdWord, Count:=1, Extend:=wdExtend
If PageVerify = "1RUN" Then
Selection.MoveDown unit:=wdLine, Count:=3
Selection.MoveRight unit:=wdCharacter, Count:=40, Extend:=wdExtend
Vendor2 = Trim(Selection.Text)
If Vendor1 <> Vendor2 Or i = TotalPages Then
If i = TotalPages Then
EndPage = i
Else
EndPage = i - 1
End If
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=StartPage
Set rgePages = Selection.Range
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=EndPage
rgePages.End = Selection.Bookmarks("\Page").Range.End
rgePages.Select
rgePages.Copy
Set docNew = Application.Documents.Add
docNew.Bookmarks("\EndOfDoc").Range.Paste
'format new document the same as the main document
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.92)
.BottomMargin = InchesToPoints(0.92)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(11)
.PageHeight = InchesToPoints(8.5)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
.LayoutMode = wdLayoutModeDefault
End With
Selection.WholeStory
Selection.Font.Size = 8
Selection.MoveUp unit:=wdLine, Count:=1
Selection.HomeKey unit:=wdStory
'insert divider
With ActiveDocument.Content.Find
.ClearFormatting
Do While .Execute(FindText:="TOTAL NEW PURCHASE", Forward:=True, _
Format:=True) = True
With .Parent
.Select
Selection.MoveDown unit:=wdLine, Count:=1
'Selection.TypeParagraph
Selection.Font.Size = 24
Selection.Font.Bold = True
Selection.Font.Color = wdColorRed
Selection.TypeText Text:= _
"____________________________________________"
Selection.TypeParagraph
End With
Loop
End With
If Vendor1 = "" Then GoTo NoSave
docNew.SaveAs SavePath & "" & Vendor1 & " " & ReportTrailer
NoSave:
docNew.Close False
StartPage = i
Vendor1 = Vendor2
End If
End If
Next i
Application.ScreenUpdating = True
Documents(ReportToOpen).Close False
End Sub
]
Any help would be greatly appreciated!!