|
楼主 |
发表于 2024-9-26 08:35
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Private Sub UserForm_Initialize()
- Dim i As Integer
- For i = 1 To 43
- Me.Controls("TextBox" & i).BackColor = vbButtonFace
- Next i
- End Sub
- 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 & "\照片" ' 替换为你的搜索值
- ' 首先尝试查找.jpg文件
- fileName = Dir(folderPath & "" & searchValue48 & ".JPG")
- ' 如果没有找到.jpg文件,则尝试查找.png文件
- If fileName = "" Then
- fileName = Dir(folderPath & "" & searchValue48 & ".PNG")
- End If
- ' 如果找到了文件,则加载图片
- If fileName <> "" Then
- photoPath = folderPath & "" & fileName
- UserForm1.Image1.Picture = LoadPicture(photoPath)
- UserForm1.Image1.PictureSizeMode = fmPictureSizeModeStretch
- Else
- UserForm1.Image1.Picture = Nothing
- End If
- searchValue46 = Me.TextBox46.Value
-
- searchValue48 = Me.TextBox48.Value
-
- Set ws = ThisWorkbook.Sheets("查询记录")
-
- lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
-
- ' 记录查询内容
- ws.Cells(lastRow, 1).Value = Me.ComboBox1.Value
-
- ws.Cells(lastRow, 2).Value = searchValue46
-
- ws.Cells(lastRow, 3).Value = searchValue48
-
- ws.Cells(lastRow, 4).Value = Now
-
- End Sub
复制代码
老师,这是我写的代码,我的需求是查询出来的窗体信息进行截图放到一个文件夹内,到时候会把这些图片在电视屏幕上进行滚动播放 |
|