我正在运行Excel 2016 (64位),并得到一个‘编译错误:方法或数据成员找不到’,突出显示文本框名称。
我想不出我为什么会犯这个错误。我复制了我已经在另一个项目( 32位)中创建的代码,因为它在32位环境中完美地工作。
由于32位Vs 64位平台的冲突,我已经查找了所遇到的问题。但是我找不到编译错误的原因,因为我目前还没有其他地方的代码。
请有人告诉我在哪里和为什么会出现问题,我在名为Frm_AFI的Userform中有以下代码
选项显式Dim wb作为ThisWorkbook Dim wsLog As cnServiceLog‘cnServiceLog是我的“服务日志”工作表的代号
Private Sub UserForm_Initialize()
TXT_Date_Created.Value = Format(Date, "dd/mm/yyyy")
Dim irow As Long
Dim wsLog As cnServiceLog
Set wsLog = cnServiceLog
Dim lastRow As String
'find last data row from cnServiceLog
irow = wsLog.Cells(Rows.Count, 1).End(xlUp).Row
wsLog.TXTWorkOrderNo.Text = "SWC" & Year(Date) & Format(Month(Date), "00") & "-" & Format(Split(wsLog.Cells(irow, 1).Value, "-")(1) + 1, "00000")
End Sub
Sub getsettings()
On Error Resume Next
wb = ThisWorkbook.Worksheets(cnServiceLog).Name
If Not Err.Number = 0 Then
MsgBox "expected to find a Service Log worksheet, but it is missing"
Exit Sub
End If
On Error GoTo 0
ThisWorkbook.Worksheets(cnServiceLog).Select
x = Range("A2").Value
End Sub只是一个注意事项,:这个用户表单必须与32位和64位excel平台兼容。
提前感谢你,
TheShyButterfly
发布于 2017-06-16 04:35:57
看起来您的cnServiceLog表使用的是ActiveX控件。按照https://technet.microsoft.com/en-us/library/ee681792.aspx的说法,如果您想坚持使用ActiveX控件,就必须发布32位版本的工作簿,以及使用可用64位版本的控件的64位版本。
假设您只使用没有事件的ActiveX控件,您可能可以切换到一个非ActiveX控件,并在32位和64位主机中安全地使用单个工作簿。
TXTWorkOrderNo然后删除这行VBA
wsLog.TXTWorkOrderNo.Text = "SWC" & Year(Date) & Format(Month(Date), "00") & "-" & Format(Split(wsLog.Cells(irow, 1).Value, "-")(1) + 1, "00000")用这些线代替
Dim shp As TextBox`
Set shp = wsLog.Shapes("TXTWorkOrderNo").OLEFormat.Object
shp.Text = "SWC" & Year(Date) & Format(Month(Date), "00") & "-" & Format(Split(wsLog.Cells(irow, 1).Value, "-")(1) + 1, "00000")https://stackoverflow.com/questions/44580566
复制相似问题