Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Dec 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro to Change In-Text Citation Font Size

    With some help from the FAQ-section of BibWord I created a macro to change the font size of the In-text Citation (from Calibri 11 to Calibri 9).
    The Macro does run, but doesn't change anything and I don't know why.
    Can anybody help me with this problem?

    This is the Macro I used:

    Sub ApplyCitationStyle()
    Dim stylename As String
    Dim exists As Boolean
    Dim s As Style
    Dim fld As Field

    stylename = "In-Text Citation"

    ' Check if the style already exists.
    exists = False

    For Each s In ActiveDocument.Styles
    If s.NameLocal = stylename Then
    exists = True
    Exit For
    End If
    Next

    ' If the style did not exist yet, create it.
    If exists = False Then
    Set s = ActiveDocument.Styles.Add(stylename, wdStyleTypeCharacter)
    s.BaseStyle = ActiveDocument.Styles(wdStyleDefaultParagraphFont) .BaseStyle
    Selection.Font.Size = 9 = True
    End If

    ' Now that the style really exists, select it.
    Set s = ActiveDocument.Styles(stylename)

    ' Apply the style to all in-text citations.
    For Each fld In ActiveDocument.Fields
    If fld.Type = wdFieldCitation Then
    fld.Select
    Selection.Style = s
    End If
    Next

    End Sub

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,548
    Thanks
    3
    Thanked 149 Times in 142 Posts
    There were several problems with the code you posted. Try this version
    Code:
    Sub ApplyCitationStyle()
      Dim stylename As String
      Dim exists As Boolean
      Dim s As Style
      Dim fld As Field
      
      stylename = "In-Text Citation"
      
      ' Check if the style already exists.
      exists = False
      For Each s In ActiveDocument.Styles
        If s.NameLocal = stylename Then
          exists = True
          Exit For
        End If
      Next
      
      ' If the style did not exist yet, create it.
      If exists = False Then ActiveDocument.Styles.Add stylename, wdStyleTypeCharacter
    
      ' Change style attributes
      Set s = ActiveDocument.Styles(stylename)
      s.BaseStyle = ActiveDocument.Styles(wdStyleDefaultParagraphFont)
      s.Font.Size = 9
      
      ' Apply the style to all in-text citations.
      For Each fld In ActiveDocument.Fields
        If fld.Type = wdFieldCitation Then
          fld.Result.Style = ActiveDocument.Styles(stylename)
        End If
      Next
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,977
    Thanks
    0
    Thanked 207 Times in 188 Posts
    try:
    Code:
    Sub ApplyCitationStyle()
    Application.ScreenUpdating = False
    Dim stylename As String, exists As Boolean
    Dim s As Style, fld As Field, Rng As Range
    stylename = "In-Text Citation"
    ' Check if the style already exists.
    exists = False
    With ActiveDocument
      For Each s In .Styles
        If s.NameLocal = stylename Then
          exists = True
          Exit For
        End If
      Next
    
      ' If the style did not exist yet, create it.
      If exists = False Then
        .Styles.Add stylename, wdStyleTypeCharacter
      End If
      .Styles(stylename).BaseStyle = "Default Paragraph Font"
      .Styles(stylename).Font.Size = 9
      ' Now that the style really exists, use it.
      Set s = .Styles(stylename)
    
      ' Apply the style to all in-text citations.
      For Each fld In .Fields
        If fld.Type = wdFieldCitation Then
          Set Rng = .Range(fld.Result.Start, fld.Result.End)
          fld.ShowCodes = True
          With Rng
            .Start = .Start - 2
            .End = .End + 2
            .Style = s
          End With
          fld.ShowCodes = False
        End If
      Next
    End With
    Application.ScreenUpdating = True
    End Sub
    PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •