Insert formatted text in word header / footer through access vba (1 Viewer)

bokarinho

Registered User.
Local time
Today, 11:40
Joined
Mar 31, 2010
Messages
38
Hello,

I have a problem and i need your advice. I am creating an access software that browses for a folder with *.doc(x) files and for each one of these adds custom text with formatting at the end (as a new line) of each selected section, meaning header or footer.
I have managed to create the whole functionallity however although i can insert at the end of the header text, no formatting is available and any change to formatting commands effects all header or footer content. I want to add a new line at the end of the header with a formatting diffirent than the previous lines.

I give a piece of my code.

PHP:
Sub InsertHeaderFooter(ByRef ws As Word.Document, ByRef wordObj As Word.Application)
On Error Resume Next
' inserts the same header/footer in all worksheets
Dim fSz As String
Dim Color As String
Dim bold As Boolean
Dim ital As Boolean
Dim under As Boolean
Dim paragraph As Word.paragraph
Color = ""
bold = False
ital = False
under = False
'Global choices.
If Me.FontSz.Value < 10 Then
    fSz = "0" & CStr(Me.FontSz.Value)
Else
    fSz = CStr(Me.FontSz.Value)
End If
'Get the color from the combo.
If Me.Color.Value <> "" Then
    Color = Me.Color.Column(2)
End If
If Me.BoldIt.Value = -1 Then
    bold = True
End If
If Me.Italics.Value = -1 Then
    ital = True
End If
If Me.UnderLine.Value = -1 Then
    under = True
End If
    'Application.StatusBar = False
If Me.leftheader.Value = -1 Then
    'Go the next line.
    'Add the font here.
    'ws.Sections(1).Headers(wdHeaderFooterPrimary).Range.Font.Name = Me.fName.Value
    'ws.Sections(1).Headers(wdHeaderFooterPrimary).Range.Font.Size = CInt(Me.FontSz.Value)
    If Color <> "" Then
        ' TO DO
    End If
'Add the text.
    If bold Then
        wordObj.Selection.Font.bold = wdToggle
    End If
    If wordObj.Selection.Font.UnderLine = wdUnderlineNone And under Then
        wordObj.Selection.Font.UnderLine = wdUnderlineSingle
    Else
       wordObj.Selection.Font.UnderLine = wdUnderlineNone
    End If
    If ital Then
        wordObj.Selection.Font.Italic = wdToggle
    End If
    wordObj.Selection.Font.Size = CStr(Me.FontSz.Value)
    wordObj.Selection.Font.Color = wdColorRed
    ws.Sections(1).Headers(wdHeaderFooterPrimary).Range.InsertParagraphAfter
    ws.Sections(1).Headers(wdHeaderFooterPrimary).Range.InsertAfter (Trim(Me.addLeftHeaderText.Value))
End If
End Sub

 
This is the routine that does the insertion and formatting. However it does not work as expected above. What am i doing wrong? Thanks in advance.
 

vbaInet

AWF VIP
Local time
Today, 09:40
Joined
Jan 22, 2010
Messages
26,374
bokarinho you will need to ask this question in the Word section of the site or in appropriate Word VBA forum. This section is for Access VBA.

I'll ask the mods to move it for you.
 

bokarinho

Registered User.
Local time
Today, 11:40
Joined
Mar 31, 2010
Messages
38
Can anyone help me please?
 

vbaInet

AWF VIP
Local time
Today, 09:40
Joined
Jan 22, 2010
Messages
26,374
I don't think the Word VBA section of this forum is very active or perhaps no one on here knows the answer.

Isn't there a way to record macros in Word? I'm almost certain you can so if you can find the trick for doing that manually, you can record a macro to get it done. Then change the code to suit.

From memory I know you can have different Headers for the first page and the rest the same, and different Headers for odd and even pages.
 

Users who are viewing this thread

Top Bottom