在第一个单元格VBA Word

时间:2019-07-18 10:04:06

标签: vba ms-word

我正在尝试创建一个函数,该函数从单词表中获取字符串数据,并基于特定单元格中的字符串来触发适合于该字符串的模块。 我下面的函数触发该模块,但在第一次成功执行“ If”后结束(如果在单元格1,3中有一个字符串“ Service”,它将触发模块ServiceAvalible.GreenButton end在此之后结束循环)。

Public Sub StatusesLoop()

    Dim oTbl As Table
    Dim CellText As String

    Set oTbl = ActiveDocument.Tables(3)

    For Each oRow In oTbl.Rows
    Set oCell = oRow.Cells(3)

        CellText = Left(oCell, Len(oCell) - 1)

        MsgBox CellText
        'Do something with each cell
        If InStr(CellText, "Service") Then
        Call ServiceAvalible.GreenButton
        Else: MsgBox "No Service Avalible"
        End If

        If InStr(CellText, "Outage") Then
        Call Outage.RedButton
        Else: MsgBox "No Outage"
        End If

        If InStr(CellText, "Deg") Then
        Call Degradation.OrangeButton
        Else: MsgBox "No Degradation"
        End If

    Next

End Sub

每个子功能看起来都一样

Public Sub GreenButton()
Application.ScreenUpdating = False
Selection.GoTo What:=wdGoToBookmark, Name:="drawingArea"
Set myDocument = ActiveDocument
With myDocument.Shapes.AddShape(msoShapeRectangle, _
 665, 403, 65, 15)
 .Fill.BackColor.RGB = RGB(50, 205, 50)
 .TextFrame.TextRange.Text = "Service available"
 .TextFrame.MarginBottom = 0.05
 .TextFrame.MarginLeft = 0.05
 .TextFrame.MarginRight = 0.05
 .TextFrame.MarginTop = 0.05
 .TextFrame.AutoSize = True
 With .TextFrame.TextRange.Font
    .Bold = True
    .Name = "Arial"
    .Size = 7
    .Italic = False
    .ColorIndex = wdWhite
End With
End With
Application.ScreenUpdating = True
End Sub

我想检查此函数中的每个If语句。谢谢您的帮助。

0 个答案:

没有答案