2017-06-13 27 views
0

因此,在创建表格后,我有一列Yes,No和N/A,需要绿色表示是,红色表示否,灰色表示N /一个。不是整列只是列。需要在Access中搜索由VBA创建的Powerpoint表中的特定文本

我不是一个初学者,但我不是在编码方面的专家...这里是我的代码:

With .Shapes.AddTable(5, 5, 0, 140, 720, 40)          
' NumRows/NumColumns/Left/Top/Width/Height 
    .Table.ApplyStyle "{5940675A-B579-460E-94D1-54222C63F5DA}"     
    ' Table Style for No Style, Table Grid 
    .Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "Text1" 
    .Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = "TeXT2" 
    .Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = "Text3" 
    .Table.Cell(1, 4).Shape.TextFrame.TextRange.Text = "Text4" 
    .Table.Cell(1, 5).Shape.TextFrame.TextRange.Text = "Text5" 
    R = 1 
    With .Table 
    For C = 1 To 5 
     .Cell(R, C).Shape.TextFrame.TextRange.Font.Size = 8 
     .Cell(R, C).Shape.TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255) 
     .Cell(R, C).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter 
    Next 
    R = R + 1 
    End With 

    .Table.Columns(1).Width = 140 
    .Table.Columns(2).Width = 60 
    .Table.Columns(3).Width = 60 
    .Table.Columns(4).Width = 100 
    .Table.Columns(5).Width = 360 
    .Fill.BackColor.RGB = RGB(255, 255, 255) 
    For Each cl In .Table.Rows(1).Cells 
    cl.Shape.Fill.BackColor.RGB = RGB(0, 32, 96) 
    cl.Shape.Fill.ForeColor.RGB = RGB(0, 32, 96) 
    cl.Shape.TextFrame.TextRange.Characters.Font.Bold = True 
    cl.Shape.TextFrame.VerticalAnchor = msoAnchorBottom 
    Next cl 

    ' Adding data to table ------------------------ 
    R = 2 
    With .Table 
    While Not rs26.EOF 
     For C = 1 To 5 
     .Cell(R, C).Shape.TextFrame.TextRange.Text = Nz(rs26.Fields(C - 1)) 
     .Cell(R, C).Shape.TextFrame.TextRange.Font.Size = 8 
     .Cell(R, C).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft 
     Next 'c column 
     rs26.MoveNext 
     R = R + 1 
    Wend 
    rs26.Close 
    End With 

    ' Having trouble getting this part of the code to work ------------------ 
    With .Table 
    If .Cell(R, 2).Shape.TextFrame.TextRange.Text = "No" Then 
     .Cell(R, 2).Shape.Fill.BackColor.RGB = RGB(255, 0, 0) ' Red 
     .Cell(R, 2).Shape.Fill.ForeColor.RGB = RGB(255, 0, 0) 
    ElseIf .Cell(R, 2).Shape.TextFrame.TextRange.Text = "Yes" Then 
     .Cell(R, 2).Shape.Fill.BackColor.RGB = RGB(146, 208, 80) ' Green 
     .Cell(R, 2).Shape.Fill.ForeColor.RGB = RGB(146, 208, 80) 
    Else 
     .Cell(R, 2).Shape.Fill.BackColor.RGB = RGB(166, 166, 166) ' Gray 
     .Cell(R, 2).Shape.Fill.ForeColor.RGB = RGB(166, 166, 166) 
    End If 
    End With 

End With ' table for chart 

我把注释行上面的代码我遇到的问题。当它到达代码的这部分时,它停止运行。

我试过把这部分代码放在几个不同的地方,但仍然无法工作。

希望我已经提供了足够的信息给有人帮助。

谢谢你的时间。

回答

0

好吧,自从我发布这个问题后,我继续玩弄代码并提出了答案。我知道一个IF ... THEN会的工作,我只是摆在正确的组合,一旦我做了,我得到了代码工作...见下面的解决方案:

R = 2 
    With .Table 
     While Not rs26.EOF 
     For C = 1 To 5 
     .Cell(R, C).Shape.TextFrame.TextRange.Text = Nz(rs26.Fields(C - 1)) 
     .Cell(R, C).Shape.TextFrame.TextRange.Font.Size = 8 
     .Cell(R, C).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft 
      If Nz(rs26.Fields(2 - 1)) = "Yes" Then 
      .Cell(R, 2).Shape.Fill.ForeColor.RGB = RGB(146,208,80) 'Green 
      .Cell(R, 2).Shape.Fill.BackColor.RGB = RGB(146, 208, 80) 
      .Cell(R, 2).Shape.TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255) 
      .Cell(R, 2).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter 
      ElseIf Nz(rs26.Fields(2 - 1)) = "No" Then 
      .Cell(R, 2).Shape.Fill.ForeColor.RGB = RGB(255, 0, 0) 'Red 
      .Cell(R, 2).Shape.Fill.BackColor.RGB = RGB(255, 0, 0) 
      .Cell(R, 2).Shape.TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255) 
      .Cell(R, 2).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter 
      Else 
      .Cell(R, 2).Shape.Fill.BackColor.RGB = RGB(166, 166, 166) ' Gray 
      .Cell(R, 2).Shape.Fill.ForeColor.RGB = RGB(166, 166, 166) 
      .Cell(R, 2).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter 
      End If 
     Next 'c column 
     rs26.MoveNext 
     R = R + 1 
     Wend 
     rs26.Close 
    End With 

我基本上嵌入IF ... FOR语句中的THEN语句在数据加载到表中时。数据已经在表格中之前,我正在尝试做这件事。