VBA为“行列表”中的文本着色

时间:2018-07-30 13:24:25

标签: excel vba excel-vba

有没有办法用下拉列表中的颜色给出一个简短的单词?我已经设法使代码可以将颜色设置为背景,但不能将文本设置为颜色,而不会出现错误消息。

  @Action(FetchFolders)
  FetchFolders(state: StateContext<DocumentStateModel>, { payload }: FetchFolders) {
    console.log('inside');
    return this.http.get(`assets/fake-data/${payload}/documents.json`)
      .pipe(
        tap(result => this.store.dispatch(new ReceiveFolders(<DocumentFolder[]>result)))
      );
  }

这是我的职能。当我想为背景添加颜色时,它可以工作(此功能为单词@NgModule({ imports: [ CommonModule, MenuModule, FormModule, RouterModule, NgxsModule.forFeature([DocumentState]) ], declarations: [DocumentListComponent, DocumentsComponent], exports: [DocumentsComponent] }) export class DocumentModule { } 提供红色背景)。但我的目标是将单词' Create a cell with drop down menu and color formatting, this is specifide for a cell Sub CreateRequirementAcceptanceDropDownCell(CurrentCell As Range) ' ' CreateDataValidationCell Macro ' Dim dvLists(1 To 4) As String 'data validation area dvLists(1) = "Accepted" dvLists(2) = "Accepted with Deviation" dvLists(3) = "Not Accepted" dvLists(4) = "Not Confirmed" CurrentCell.Select With Selection.Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:=Join(dvLists, ",") .IgnoreBlank = False .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With ' Colour background, but can´t colour text.... ColorizeStatus Selection.Value = "Not Confirmed" End Sub Sub ColorizeStatusText(ColorRange As Range) ColorRange.Select '------------ Applicable ---- Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _ Formula1:="=""Not Accepted""" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 255 ' red .TintAndShade = 0 End With '--------------------------------------------------- Selection.FormatConditions(1).StopIfTrue = False End Sub 更改为红色,而不更改背景。我尝试在不同的情况下使用"Not Accepted",但是没有用...是否可以更改此函数中的文本颜色?谢谢

1 个答案:

答案 0 :(得分:0)

如以上评论所述:

With Selection.FormatConditions(1).Font
         .Color = RGB(255, 0, 0) ' red
        .TintAndShade = 0
End With