请教Word中如何用VBA 将所有图片加上边框

请教Word中如何用VBA 将所有图片加上边框,第1张

只要一句代码?那就给你一句参考一下吧:picCount = ActiveDocument.InlineShapes.Count '计算文件中图片数目在Word中,插入的图片已被转化为 InlineShape 对象。之后用For循环语句,给所有图片加黑色边框。单个图片加边框的语句,你自己可以录制一个宏看看,将录制的宏代码拷贝到For循环中修改一下即可。

___________________________________________________________________

单个图片加边框,你自己录制宏就可以看到代码了,这是学习VBA的必由之路啊。选中一张图片,工具-宏-录制新宏,然后,格式-边框和阴影,给图片加上黑边框,然后,alt+F11打开VB编译器,就看到代码了。本想只授人以渔即足够了,但犹豫了一下,还是贴给你吧:

With Selection.InlineShapes(1)

With .Borders(wdBorderLeft)

.LineStyle = wdLineStyleSingle

.LineWidth = wdLineWidth050pt

.Color = wdColorAutomatic

End With

With .Borders(wdBorderRight)

.LineStyle = wdLineStyleSingle

.LineWidth = wdLineWidth050pt

.Color = wdColorAutomatic

End With

With .Borders(wdBorderTop)

.LineStyle = wdLineStyleSingle

.LineWidth = wdLineWidth050pt

.Color = wdColorAutomatic

End With

With .Borders(wdBorderBottom)

.LineStyle = wdLineStyleSingle

.LineWidth = wdLineWidth050pt

.Color = wdColorAutomatic

End With

.Borders.Shadow = False

End With

With Options

.DefaultBorderLineStyle = wdLineStyleSingle

.DefaultBorderLineWidth = wdLineWidth050pt

.DefaultBorderColor = wdColorAutomatic

End With

计算图片数目是为了For循环用的,有多少图片就要循环多少次,给所有图片都加上边框。

For i = 1 to picCount

......

Next i

中间就是上面那段代码,把InlineShapes(1)改为InlineShapes(i)

1:在第一个单元格插入复选框后拖动复制。

2:如果单元格区域不规则可以用下面代码:

Private Sub AddCheckBoxesInRange()

On Error Resume Next

Dim cell As Range

Dim CurrentRange As Range

Set CurrentRange = Selection

CurrentRange.NumberFormatLocal = ""

Application.ScreenUpdating = False

For Each cell In CurrentRange

ActiveSheet.CheckBoxes.Add(cell.Left, cell.Top, cell.Height, cell.Height).Select

With Selection

.Value = xlOff

.LinkedCell = cell.Address

.Display3DShading = False

.Characters.Text = ""

End With

Next

CurrentRange.Select

Application.ScreenUpdating = True

Set cell = Nothing

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11640565.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存