提问人:St3althPatchin 提问时间:8/17/2023 更新时间:8/17/2023 访问量:51
为什么 Excel 说我的 ActiveX 对象不在工作表上?
Why is Excel saying that my ActiveX object is not on the Worksheet?
问:
我正在尝试使用 BarcodeTools 的数据矩阵 ActiveX 对象,以便能够在我的 excel 工作表上创建数据矩阵代码。我希望在条形码中编码的数据是通过我的用户消息探测数据。这是因为我正在寻找打印它以供以后扫描。无论出于何种原因,我都无法让 excel 验证我的工作表上是否有 ActiveX 对象。
我可以把它放在工作表中。但是当我单步执行代码时,似乎我所拥有的检查显示那里什么都没有。
我不确定使用此ActiveX工具是否缺少某些内容。特别是因为当宏运行时,我仍然需要打印条形码。但它不是使用用户将创建的字符串进行编码的。我知道条形码工具已将其条形码设置为添加的 ActiveX 对象。当我右键单击条形码时,我可以看到它的属性。我只是不确定为什么当我为链接单元格 A1 设置时条形码没有获取代码,什么也没发生。当我尝试更改该属性和数据编码属性时,没有任何变化。
Public Sub CreateAndPrintLabel()
Dim createLabel As VbMsgBoxResult
Dim labelInfo As String
Dim sPath As String
Dim ObjDoc As Object
' Step 1: Ask the user if they wish to create a label
createLabel = MsgBox("Do you wish to create a label?", vbYesNo)
If createLabel = vbYes Then
' Step 2: Prompt for each parameter
licensePlate = InputBox("Enter License Plate:")
partNumber = InputBox("Enter Part Number:")
Description = InputBox("Enter Description:")
ExpirationDate = InputBox("Enter Expiration Date:")
' Step 3: Validate and display entered information
labelInfo = licensePlate & " | " & partNumber & " | " & Description & " | " & ExpirationDate
confirmMsg = "Is the following information correct?" & vbCrLf & vbCrLf & labelInfo
confirmed = MsgBox(confirmMsg, vbYesNo) = vbYes
' Step 4: Allow correction or confirmation
If Not confirmed Then
' Provide an option to go through the steps again if the information was incorrect
Call CreateAndPrintLabel
Exit Sub
End If
' Store labelInfo in cell A1 on Sheet1
ThisWorkbook.Sheets("Sheet1").Range("A1").Value = labelInfo
' Check if Data Matrix data matches the content in cell A1
Dim dataMatrixControl1 As OLEObject
On Error Resume Next
Set dataMatrixControl1 = ThisWorkbook.Sheets("Sheet1").OLEObjects("DataMatrixCtrl.1")
On Error GoTo 0
If Not dataMatrixControl1 Is Nothing Then
If dataMatrixControl1.Object.DataToEncode = labelInfo Then
' Step 5: Print the label using Brother printer
Set ObjDoc = CreateObject("bpac.Document")
sPath = "C:\Users\giovanni.fontanetta\Documents\My Labels\Matrix.lbx"
' Open lbx file
If ObjDoc.Open(sPath) Then
' Set text for the entire label
ObjDoc.SetText 0, dataMatrixContent
' Print the label
ObjDoc.StartPrint "", bpoDefault
ObjDoc.PrintOut 1, bpoDefault
ObjDoc.EndPrint
' Close lbx file
ObjDoc.Close
Else
MsgBox "Failed to open label file."
End If
Else
MsgBox "Data Matrix content does not match A1."
End If
Else
MsgBox "ActiveX Data Matrix control not found on the sheet."
End If
End If
End Sub
Sub Print_Label()
Dim bRet As Boolean
Dim sPath As String
Dim ObjDoc As bpac.Document
Set ObjDoc = CreateObject("bpac.Document")
sPath = "C:\Users\giovanni.fontanetta\Documents\My Labels\Matrix.lbx"
'Open lbx file
bRet = ObjDoc.Open(sPath)
If (bRet <> False) Then
' Start Print-Setting
ObjDoc.StartPrint "", bpoDefault
ObjDoc.PrintOut 1, bpoDefault
' Finish Print-Setting.iStart the printing.j
ObjDoc.EndPrint
' Close lbx file
ObjDoc.Close
End If
End Sub
答: 暂无答案
评论
Dim obj As Object: For Each obj In ThisWorkbook.Sheets("Sheet1").OLEObjects: Debug.Print obj.Name:Next