gpt4 book ai didi

vba - 内容控制无法识别内容

转载 作者:行者123 更新时间:2023-12-03 08:17:02 25 4
gpt4 key购买 nike

我希望有人可以帮助我弄清楚为什么当Count值为5时,以下代码中的'F'值继续在ErrorMessage字符串中包含我的错误标签吗?
在文档中,内容控件包含与所有其他控件一样的文本(它们可以正常工作),但是在VBA代码中无法识别此内容控件文本值以映射错误标签。
尝试仅替换控件并检查属性是否匹配。调试消息提示该值只是被设置为默认的“内容控制值”“单击或点击此处输入文本”。

Private Sub Create_Click()
Dim oCC As ContentControl
Dim oCC2 As ContentControl

Dim Mandatory(9) As String
Dim ErrorMessage As String
Dim ErrorCount As Integer
Dim ErrorLabel(9) As String

Dim objDoc As Document
Dim strFilename As String
Dim strFileString As String
Dim Number As String

Mandatory(0) = "A"
Mandatory(1) = "B"
Mandatory(2) = "C"
Mandatory(3) = "D"
Mandatory(4) = "E"
Mandatory(5) = "F"
Mandatory(6) = "G"
Mandatory(7) = "H"
Mandatory(8) = "I"

ErrorLabel(0) = "A Label"
ErrorLabel(1) = "B Label"
ErrorLabel(2) = "C Label"
ErrorLabel(3) = "D Label"
ErrorLabel(4) = "E Label"
ErrorLabel(5) = "F Label"
ErrorLabel(6) = "G Label"
ErrorLabel(7) = "H Label"
ErrorLabel(8) = "I Label"

ErrorMessage = ""

ErrorMessage = "The following mandatory fields are missing: "

For Count = 0 To 8

Set oCC = ActiveDocument.SelectContentControlsByTitle(Mandatory(Count)).Item(1)
MsgBox (oCC.Range.Text)


If Count = 0 Then

Number = ActiveDocument.SelectContentControlsByTitle(Mandatory(Count)).Item(1).Range.Text

End If

If oCC.Range.Text = "Click or tap here to enter text." Or oCC.Range.Text = "0.00" Then

ErrorMessage = ErrorMessage & vbCrLf & vbCrLf & "- " & ErrorLabel(Count)
MsgBox (oCC.Range.Text)

ErrorCount = ErrorCount + 1

End If
Next Count

If ErrorCount > 0 Then

MsgBox (ErrorMessage)

Else

strFileString = Number

MsgBox (strFileString)

strFilename = "Some Text Here" & " - " & strFileString & ".pdf"

With ActiveDocument

NewPath = .Path & "\" & strFilename
.SaveAs2 FileName:=NewPath, FileFormat:=wdFormatPDF
.ExportAsFixedFormat OutputFileName:=strFilename, ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, Item:=wdExportDocumentContent

End With
End If

End Sub

最佳答案

检查文档中是否没有其他具有相同标题的内容控件。

关于vba - 内容控制无法识别内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65271465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com