Skip to main content

Header & footer Macro code

  • August 15, 2017
  • 3 replies
  • 0 views

Hi,

 

Could some one provide macro code to convert  rumba report output in PDF  format.

 

Create Header & footer across all the pages like same as word document.

 

Thankls 


#Rumba

3 replies

Hi,

 

Could some one provide macro code to convert  rumba report output in PDF  format.

 

Create Header & footer across all the pages like same as word document.

 

Thankls 


#Rumba

Hi Sesha567

I believe we have the Report to PDF bits covered in the other thread: https://community.microfocus.com/microfocus/mainframe_solutions/rumba/f/52f94606-8317-4e71-a3ee-137fefbc9823/19617/schedule-rumba-ouptut-in-email 

As for the Create Header & Footer across all the pages like in a word document, this is achievable in conjunction with the the macro from the thread above.

Unfortunately the Rumba Basic Engine don't handle the MS Office "Range" object very well, so in order to be able to get the Header and Footers automatically populated you need to do so from VBA.

Here is some sample code.

    Dim wrdDoc As Word.Document
    Set wrdDoc = Application.ActiveDocument
 
    Dim HeaderText As String
    Dim HeaderRange As Object

    Set HeaderRange = wrdDoc.Sections.Item(1).Headers(1).Range

    HeaderText = "This is my Header Text"
    HeaderRange.Text = HeaderText
    HeaderRange.Font.Name = "Castellar"

    HeaderRange.Font.Bold = True
    HeaderRange.Font.Italic = True
    HeaderRange.Font.Size = 18
    HeaderRange.Font.ColorIndex = wdTeal

    Dim FooterText As String
    Dim FooterRange As Object

    Set FooterRange = wrdDoc.Sections.Item(1).Footers(1).Range

    FooterText = "This is my Footer Text" & vbTab & vbTab & "Page: "
    FooterRange.Font.Name = "Times New Roman"
    FooterRange.Font.Bold = True
    FooterRange.Text = FooterText

    wrdDoc.Sections.Item(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add 2, True

That problem here is that you need this code to execute when you open your txt document in MS Word, alas your work document does not contain a VBA project. There are a couple of ways around this 

a) Use the VBIDE to inject the macro code into the VBA project which gets created when you open the txt file in MS Word from your RUMBA script, and programatically execute the VBA macro from your Rumba script.

b) Use a template in MS Word (Normal.dot), and have the template store the macro code. This way you can wrap the code above in an if the document name is XXX.yyy then ... esle do nothing. Then you have the code execute on the Document Open event.

Here is how it would look, using the code above.

    Private Sub Document_Open()

        If Application.ActiveDocument.FullName = "C:\\temp\\MyReportFileName.txt" Then

            Dim wrdDoc As Word.Document
            Set wrdDoc = Application.ActiveDocument
 
            Dim HeaderText As String
            Dim HeaderRange As Object

            Set HeaderRange = wrdDoc.Sections.Item(1).Headers(1).Range

            HeaderText = "This is my Header Text"
            HeaderRange.Text = HeaderText
            HeaderRange.Font.Name = "Castellar"

            HeaderRange.Font.Bold = True
            HeaderRange.Font.Italic = True
            HeaderRange.Font.Size = 18
            HeaderRange.Font.ColorIndex = wdTeal

            Dim FooterText As String
            Dim FooterRange As Object

            Set FooterRange = wrdDoc.Sections.Item(1).Footers(1).Range

            FooterText = "This is my Footer Text" & vbTab & vbTab & "Page: "
            FooterRange.Font.Name = "Times New Roman"
            FooterRange.Font.Bold = True
            FooterRange.Text = FooterText

            wrdDoc.Sections.Item(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add 2, True
       End If
    End Sub

Tom

 


Hi,

 

Could some one provide macro code to convert  rumba report output in PDF  format.

 

Create Header & footer across all the pages like same as word document.

 

Thankls 


#Rumba

Hi Sesha567

I believe we have the Report to PDF bits covered in the other thread: https://community.microfocus.com/microfocus/mainframe_solutions/rumba/f/52f94606-8317-4e71-a3ee-137fefbc9823/19617/schedule-rumba-ouptut-in-email 

As for the Create Header & Footer across all the pages like in a word document, this is achievable in conjunction with the the macro from the thread above.

Unfortunately the Rumba Basic Engine don't handle the MS Office "Range" object very well, so in order to be able to get the Header and Footers automatically populated you need to do so from VBA.

Here is some sample code.

    Dim wrdDoc As Word.Document
    Set wrdDoc = Application.ActiveDocument
 
    Dim HeaderText As String
    Dim HeaderRange As Object

    Set HeaderRange = wrdDoc.Sections.Item(1).Headers(1).Range

    HeaderText = "This is my Header Text"
    HeaderRange.Text = HeaderText
    HeaderRange.Font.Name = "Castellar"

    HeaderRange.Font.Bold = True
    HeaderRange.Font.Italic = True
    HeaderRange.Font.Size = 18
    HeaderRange.Font.ColorIndex = wdTeal

    Dim FooterText As String
    Dim FooterRange As Object

    Set FooterRange = wrdDoc.Sections.Item(1).Footers(1).Range

    FooterText = "This is my Footer Text" & vbTab & vbTab & "Page: "
    FooterRange.Font.Name = "Times New Roman"
    FooterRange.Font.Bold = True
    FooterRange.Text = FooterText

    wrdDoc.Sections.Item(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add 2, True

That problem here is that you need this code to execute when you open your txt document in MS Word, alas your work document does not contain a VBA project. There are a couple of ways around this 

a) Use the VBIDE to inject the macro code into the VBA project which gets created when you open the txt file in MS Word from your RUMBA script, and programatically execute the VBA macro from your Rumba script.

b) Use a template in MS Word (Normal.dot), and have the template store the macro code. This way you can wrap the code above in an if the document name is XXX.yyy then ... esle do nothing. Then you have the code execute on the Document Open event.

Here is how it would look, using the code above.

    Private Sub Document_Open()

        If Application.ActiveDocument.FullName = "C:\\temp\\MyReportFileName.txt" Then

            Dim wrdDoc As Word.Document
            Set wrdDoc = Application.ActiveDocument
 
            Dim HeaderText As String
            Dim HeaderRange As Object

            Set HeaderRange = wrdDoc.Sections.Item(1).Headers(1).Range

            HeaderText = "This is my Header Text"
            HeaderRange.Text = HeaderText
            HeaderRange.Font.Name = "Castellar"

            HeaderRange.Font.Bold = True
            HeaderRange.Font.Italic = True
            HeaderRange.Font.Size = 18
            HeaderRange.Font.ColorIndex = wdTeal

            Dim FooterText As String
            Dim FooterRange As Object

            Set FooterRange = wrdDoc.Sections.Item(1).Footers(1).Range

            FooterText = "This is my Footer Text" & vbTab & vbTab & "Page: "
            FooterRange.Font.Name = "Times New Roman"
            FooterRange.Font.Bold = True
            FooterRange.Text = FooterText

            wrdDoc.Sections.Item(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add 2, True
       End If
    End Sub

Tom

 


Hi,

 

Could some one provide macro code to convert  rumba report output in PDF  format.

 

Create Header & footer across all the pages like same as word document.

 

Thankls 


#Rumba

Hi Sesha567

I believe we have the Report to PDF bits covered in the other thread: https://community.microfocus.com/microfocus/mainframe_solutions/rumba/f/52f94606-8317-4e71-a3ee-137fefbc9823/19617/schedule-rumba-ouptut-in-email 

As for the Create Header & Footer across all the pages like in a word document, this is achievable in conjunction with the the macro from the thread above.

Unfortunately the Rumba Basic Engine don't handle the MS Office "Range" object very well, so in order to be able to get the Header and Footers automatically populated you need to do so from VBA.

Here is some sample code.

    Dim wrdDoc As Word.Document
    Set wrdDoc = Application.ActiveDocument
 
    Dim HeaderText As String
    Dim HeaderRange As Object

    Set HeaderRange = wrdDoc.Sections.Item(1).Headers(1).Range

    HeaderText = "This is my Header Text"
    HeaderRange.Text = HeaderText
    HeaderRange.Font.Name = "Castellar"

    HeaderRange.Font.Bold = True
    HeaderRange.Font.Italic = True
    HeaderRange.Font.Size = 18
    HeaderRange.Font.ColorIndex = wdTeal

    Dim FooterText As String
    Dim FooterRange As Object

    Set FooterRange = wrdDoc.Sections.Item(1).Footers(1).Range

    FooterText = "This is my Footer Text" & vbTab & vbTab & "Page: "
    FooterRange.Font.Name = "Times New Roman"
    FooterRange.Font.Bold = True
    FooterRange.Text = FooterText

    wrdDoc.Sections.Item(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add 2, True

That problem here is that you need this code to execute when you open your txt document in MS Word, alas your work document does not contain a VBA project. There are a couple of ways around this 

a) Use the VBIDE to inject the macro code into the VBA project which gets created when you open the txt file in MS Word from your RUMBA script, and programatically execute the VBA macro from your Rumba script.

b) Use a template in MS Word (Normal.dot), and have the template store the macro code. This way you can wrap the code above in an if the document name is XXX.yyy then ... esle do nothing. Then you have the code execute on the Document Open event.

Here is how it would look, using the code above.

    Private Sub Document_Open()

        If Application.ActiveDocument.FullName = "C:\\temp\\MyReportFileName.txt" Then

            Dim wrdDoc As Word.Document
            Set wrdDoc = Application.ActiveDocument
 
            Dim HeaderText As String
            Dim HeaderRange As Object

            Set HeaderRange = wrdDoc.Sections.Item(1).Headers(1).Range

            HeaderText = "This is my Header Text"
            HeaderRange.Text = HeaderText
            HeaderRange.Font.Name = "Castellar"

            HeaderRange.Font.Bold = True
            HeaderRange.Font.Italic = True
            HeaderRange.Font.Size = 18
            HeaderRange.Font.ColorIndex = wdTeal

            Dim FooterText As String
            Dim FooterRange As Object

            Set FooterRange = wrdDoc.Sections.Item(1).Footers(1).Range

            FooterText = "This is my Footer Text" & vbTab & vbTab & "Page: "
            FooterRange.Font.Name = "Times New Roman"
            FooterRange.Font.Bold = True
            FooterRange.Text = FooterText

            wrdDoc.Sections.Item(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add 2, True
       End If
    End Sub

Tom