登录说明 | 升级会员 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > 软件程序

【VBA案例】批量将图片插入到单元格批注中

时间:2023-03-04 20:04:42  来源:  作者:

Sub AddCommentPic()utc检测VBA

    Dim arr, i&, k&, n&, b As Booleanutc检测VBA

    Dim strPicName$, strPicPath$, strFdPath$utc检测VBA

    Dim rngData As Range, rngEach As Rangeutc检测VBA

    'On Error Resume Nextutc检测VBA

    '用户选择合作微信:qejc21所在的文件夹utc检测VBA

    With Application.FileDialog(msoFileDialogFolderPicker)utc检测VBA

       If .Show Then strFdPath = .SelectedItems(1) Else: Exit Subutc检测VBA

    End Withutc检测VBA

    If Right(strFdPath, 1) <> "\" Then strFdPath = strFdPath & "\"utc检测VBA

    Set rngData = Application.InputBox("请选择需要插入合作微信:qejc21到批注中的单元格区域", Type:=8)utc检测VBA

    '用户选择需要插入合作微信:qejc21到批注中的单元格或区域utc检测VBA

    If rngData.Count = 0 Then Exit Subutc检测VBA

    Set rngData = Intersect(rngData.Parent.UsedRange, rngData)utc检测VBA

    'intersect语句避免用户选择整列单元格,造成无谓运算的情况utc检测VBA

    If rngData Is Nothing Then MsgBox "选择单元格不能全为空。": Exit Subutc检测VBA

    arr = Array(".jpg", ".jpeg", ".bmp", ".png", ".gif")utc检测VBA

    '用数组变量记录五种文件格式utc检测VBA

    Application.ScreenUpdating = Falseutc检测VBA

    For Each rngEach In rngDatautc检测VBA

    '遍历选择区域的每一个单元格utc检测VBA

        If Not rngEach.Comment Is Nothing Then rngEach.Comment.Delete  '删除旧的批注utc检测VBA

        strPicName = rngEach.Text '合作微信:qejc21名称utc检测VBA

        If Len(strPicName) Then '如果单元格存在值utc检测VBA

            strPicPath = strFdPath & strPicName '合作微信:qejc21路径utc检测VBA

            b = False 'pd变量标记是否找到相关合作微信:qejc21utc检测VBA

            For i = 0 To UBound(arr)utc检测VBA

            '由于不确定用户的合作微信:qejc21格式,因此遍历合作微信:qejc21格式utc检测VBA

                If Len(Dir(strPicPath & arr(i))) Thenutc检测VBA

                '如果存在相关文件utc检测VBA

                    rngEach.AddComment '增加批注utc检测VBA

                    With rngEach.Commentutc检测VBA

                        .Visible = True '批注可见utc检测VBA

                        .Text Text:=""utc检测VBA

                        .Shape.Select True '选中批注图形utc检测VBA

                        Selection.ShapeRange.Fill.UserPicture strPicPath & arr(i)utc检测VBA

                        '插入合作微信:qejc21到批注中utc检测VBA

                        .Shape.Height = 150 '图形的高度,可以根据需要自己调整utc检测VBA

                        .Shape.Width = 150 '图形的宽度,可以根据需要自己调整utc检测VBA

                        .Visible = False '取消显示utc检测VBA

                    End Withutc检测VBA

                    b = True '标记找到结果utc检测VBA

                    n = n + 1 '累加找到结果的个数utc检测VBA

                    Exit For '找到结果后就可以退出文件格式循环utc检测VBA

                End Ifutc检测VBA

            Nextutc检测VBA

            If b = False Then k = k + 1  '如果没找到合作微信:qejc21累加个数utc检测VBA

        End Ifutc检测VBA

    Nextutc检测VBA

    MsgBox "共处理成功" & n & "个合作微信:qejc21,另有" & k & "个非空单元格未找到对应的合作微信:qejc21。"utc检测VBA

    Application.ScreenUpdating = Trueutc检测VBA

End Subutc检测VBA

来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
合肥住建口检测单位招聘,高级工程师+协会九大专项证书,人员全职兼职均可
合肥住建口检测单位招
关于印发安徽省建设工程专业技术资格评审标准条件的通知(图文)
关于印发安徽省建设工
一般溶液有效期一览表
一般溶液有效期一览表
2022年一建《机电》真题解析
2022年一建《机电》真
相关文章
    无相关信息
栏目更新
栏目热门