|
楼主 |
发表于 2024-9-26 09:35
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Private Sub CommandButton1_Click()
- Dim rng48 As Range, rng46 As Range
-
- Dim i As Integer
-
- Dim searchValue48 As String, searchValue46 As String
-
- Dim folderPath As String, fileName As String, photoPath As String
- ' 获取TextBox48和TextBox46的值
-
- searchValue48 = Trim(UserForm1.TextBox48.Text)
-
- searchValue46 = Trim(UserForm1.TextBox46.Text)
- ' 检查搜索值是否为空
-
- If searchValue48 = "" Or searchValue46 = "" Or ComboBox1 = "" Then
-
- MsgBox "请输入搜索值!", vbExclamation
-
- Exit Sub
- End If
- ' 查找TextBox48对应的信息并填充到TextBox中
-
- Set rng48 = Sheet2.Range("A:A").Find(searchValue48, LookIn:=xlValues, LookAt:=xlWhole)
-
- If rng48 Is Nothing Then
-
- MsgBox "你搜索的工艺不存在(新工艺编号)", vbInformation
-
- Exit Sub
-
- End If
- ' 填充数据到文本框
- For i = 1 To 44
-
- Me.Controls("TextBox" & i).Text = rng48.Offset(0, i).Value
- Me.Controls("TextBox" & i).BackColor = vbButtonFace ' 重置背景色
- Me.Controls("TextBox" & i).ForeColor = vbBlue ' 重置前景色
-
- Next i
- ' 查找TextBox46对应的信息并对比
-
- Set rng46 = Sheet2.Range("A:A").Find(searchValue46, LookIn:=xlValues, LookAt:=xlWhole)
- If rng46 Is Nothing Then
-
- MsgBox "你搜索的工艺不存在(现有工艺编号)", vbInformation
-
- Exit Sub
-
- End If
- ' 对比TextBox48和TextBox46的信息,并设置背景色
- For i = 1 To 43
-
- If rng46.Offset(0, i).Value <> rng48.Offset(0, i).Value Then
-
- Me.Controls("TextBox" & i).ForeColor = vbRed
-
- End If
- Next i
- ' 加载图片
- folderPath = ThisWorkbook.Path & "\照片"
-
- fileName = Dir(folderPath & "" & searchValue48 & ".JPG")
-
- If fileName <> "" Then
-
- photoPath = folderPath & "" & fileName
-
- UserForm1.Image1.Picture = LoadPicture(photoPath)
-
- UserForm1.Image1.PictureSizeMode = fmPictureSizeModeStretch
-
- Else
- UserForm1.Image1.Picture = Nothing
- End If
- End Sub
复制代码 |
|