请教当excel中的数值导入到word中时,我想要求数值在20以下是红色,20到60是蓝色,60以上是绿色,宏里应该怎么写呢。 Function text()
Dim fPath As String
Dim fName As String
fPath = ActiveWorkbook.Path
fName = ActiveWorkbook.Name
Dim i As Integer
Dim docName As String
For i = 1 To Len(fName)
If Mid(fName, i, 1) = "." Then Exit For
Next i
docName = fPath & Application.PathSeparator & Left(fName, i - 1)
Dim vArray As Variant
vArray = ActiveSheet.UsedRange
Dim docContent As String
Dim r As Long, c As Integer
For r = 4 To UBound(vArray, 1)
For c = 1 To UBound(vArray, 2)
If vArray(r, 4) > 0 Then
vArray(r, 4) = Chr(32) & "高" & vArray(r, 4) & Chr(32)
Else
vArray(r, 4) = Null
End If
If vArray(r, 6) > 0 Then
vArray(r, 6) = Chr(32) & "低" & vArray(r, 6) & Chr(32)
Else
vArray(r, 6) = Null
End If
If vArray(r, 8) > 0 Then
vArray(r, 8) = Chr(32) & "初" & vArray(r, 8) & Chr(32)
Else
vArray(r, 8) = Null
End If
If c = 1 Then vArray(r, c) = vArray(r, c) & Chr(32) & Chr(32) & "(" & vArray(r, 4) & vArray(r, 6) & vArray(r, 8) & ")" & Chr(13)
If c = 2 Then vArray(r, c) = vArray(r, c) & Chr(13)
If c = 3 Then vArray(r, c) = Chr(32) & Chr(32) & Chr(32) & Chr(32) & vArray(r, c) & "(收)" & Chr(13)
If c > 3 Then vArray(r, c) = Null
docContent = docContent & vArray(r, c)
Next c
docContent = docContent & " 710068" & Chr(13) & Chr(13)
Next r
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add
wdApp.Selection.insertafter docContent
With wdApp.Selection.Font
.NameFarEast = "宋体"
.NameAscii = "宋体"
.Size = 11
.Bold = True
.Color = vbBlue
End With
End Function
Dim fPath As String
Dim fName As String
fPath = ActiveWorkbook.Path
fName = ActiveWorkbook.Name
Dim i As Integer
Dim docName As String
For i = 1 To Len(fName)
If Mid(fName, i, 1) = "." Then Exit For
Next i
docName = fPath & Application.PathSeparator & Left(fName, i - 1)
Dim vArray As Variant
vArray = ActiveSheet.UsedRange
Dim docContent As String
Dim r As Long, c As Integer
For r = 4 To UBound(vArray, 1)
For c = 1 To UBound(vArray, 2)
If vArray(r, 4) > 0 Then
vArray(r, 4) = Chr(32) & "高" & vArray(r, 4) & Chr(32)
Else
vArray(r, 4) = Null
End If
If vArray(r, 6) > 0 Then
vArray(r, 6) = Chr(32) & "低" & vArray(r, 6) & Chr(32)
Else
vArray(r, 6) = Null
End If
If vArray(r, 8) > 0 Then
vArray(r, 8) = Chr(32) & "初" & vArray(r, 8) & Chr(32)
Else
vArray(r, 8) = Null
End If
If c = 1 Then vArray(r, c) = vArray(r, c) & Chr(32) & Chr(32) & "(" & vArray(r, 4) & vArray(r, 6) & vArray(r, 8) & ")" & Chr(13)
If c = 2 Then vArray(r, c) = vArray(r, c) & Chr(13)
If c = 3 Then vArray(r, c) = Chr(32) & Chr(32) & Chr(32) & Chr(32) & vArray(r, c) & "(收)" & Chr(13)
If c > 3 Then vArray(r, c) = Null
docContent = docContent & vArray(r, c)
Next c
docContent = docContent & " 710068" & Chr(13) & Chr(13)
Next r
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add
wdApp.Selection.insertafter docContent
With wdApp.Selection.Font
.NameFarEast = "宋体"
.NameAscii = "宋体"
.Size = 11
.Bold = True
.Color = vbBlue
End With
End Function
'红色
elsif a<60 then
' 绿色
else
'蓝色
end if