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.
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.