Consulting

Results 1 to 4 of 4

Thread: Reference formatting with a Macro

  1. #1
    VBAX Regular
    Joined
    Jun 2017
    Posts
    15
    Location

    Reference formatting with a Macro

    I have am trying to automate the reference insertion. I have a macro that does that, but I basically want the figure insertion to be the same style as where it is being inserted, and I would like it to be bold...Also, I only want the those characters to be bold, so if I start typing again, it will revert back to the font that was used previously.

    What do I need to add to make that a reality?

    Sub InsertFigureReference()
    With Application.Dialogs(wdDialogInsertCrossReference)
    .ReferenceType = "Figure"
    .ReferenceKind = wdOnlyLabelAndNumber
    .InsertAsHyperlink = True
    .Show
    End With
    End Sub


    Many thanks in advance.

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Try:
    Sub InsertFigureReference()
    Application.ScreenUpdating = False
    ActiveWindow.View.ShowFieldCodes = True
    Dim Rng As Range: Set Rng = Selection.Range
    With Application.Dialogs(wdDialogInsertCrossReference)
      .ReferenceType = "Figure"
      .ReferenceKind = wdOnlyLabelAndNumber
      .InsertAsHyperlink = True
      .Show
    End With
    With Rng
      .MoveEnd wdWord, 1
      If .Fields.Count = 0 Then
        Undo
        GoTo ErrExit
      End If
      With .Fields(1)
        With .Code
          .Text = Trim(Split(.Text, "\h")(0) & "\* Charformat \h")
          .Characters.First.Style = "Strong"
        End With
        .Update
      End With
      .Collapse wdCollapseEnd
    End With
    ErrExit:
    Set Rng = Nothing
    ActiveWindow.View.ShowFieldCodes = False
    Application.ScreenUpdating = True
    End Sub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Regular
    Joined
    Jun 2017
    Posts
    15
    Location
    Thank you very much...

  4. #4
    VBAX Regular
    Joined
    Jun 2017
    Posts
    15
    Location
    I was unable to get the macro to work with the following statement:
    If .Fields.Count = 0 Then
    Undo
    GoTo ErrExit
    End If

    However, if you remove the bolded "undo", it works fine..

    Thanks again

Posting Permissions

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