View Single Post
 
Old 04-28-2017, 11:06 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Without the rest of the code, anyone trying to assist is flying blind. I think I understand the concept of what the macro is doing and the following will do that provided the values in the variables are appropriate:

Code:
Option Explicit

Sub Macro1()
Dim prevSent As Range
Dim sentNumb As Long
    If do_DocVars_Exist = True Then
        sentNumb = ActiveDocument.Variables("selNumb").Value
        If ActiveDocument.Sentences.Count >= sentNumb Then
            Set prevSent = ActiveDocument.Sentences(sentNumb)
            With prevSent
                .Select
                .Font.Size = ActiveDocument.Variables("selSize").Value
                .Font.Color = ActiveDocument.Variables("selColor").Value
                .Font.Name = ActiveDocument.Variables("selName").Value
            End With
        Else
            MsgBox "There is no sentence number " & sentNumb
        End If
    Else
        MsgBox "The required variables are not present"
    End If
End Sub

Function do_DocVars_Exist() As Boolean
Dim oVar As Variable
Dim iVar As Integer: iVar = 0

    For Each oVar In ActiveDocument.Variables
        Select Case oVar.Name
            Case "selNumb", "selSize", "selColor"
                If IsNumeric(oVar.Value) Then
                    iVar = iVar + 1
                End If
            Case "selName"
                iVar = iVar + 1
        End Select
    Next oVar
    If iVar = 4 Then do_DocVars_Exist = True
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote