得到长度:
Function CountWord(Optional word As String) As Integer
Dim i, j As Integer
i = 0
For j = 1 To Len(word)
If Asc(Mid(word, j, 1)) < 0 Then i = i + 1
i = i + 1
Next
CountWord = i
End Function
以动态添加标题为例
Private Sub ActiveReport_ReportStart()
With ReportHeader.Controls
Set ctl = .Add("DDActiveReports2.Field")
ctl.Text = RepTitle
ctl.Font.Size = 30
ctl.width = (CountWord(ctl.Text) + 1) * 10 * ctl.Font.Size
ctl.Left = (9025 - ctl.width) / 2
ctl.Top = 0
ctl.Font.Bold = True
ctl.Font.Italic = True
ctl.Font.Name = "宋体"
ctl.ForeColor = &H800000
End With
Me.Caption = RepTitle
TxtDate.Text = format(Now, "yyyy-mm-dd hh:nn")
End Sub