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. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,458
    Thanks
    3
    Thanked 128 Times in 121 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

  4. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,805
    Thanks
    0
    Thanked 166 Times in 153 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
  •