一、用vba给word的 表格中的图片 加边框时 边框加到表格上
经测试编写VBA代码如下:
Sub 嵌入式图片加边框()
Application.ScreenUpdating = False
Dim a As Integer
Dim pic As InlineShape
Dim aBorder As Border
a = ActiveDocument.InlineShapes.Count
If a = 0 Then
MsgBox ("没有发现嵌入式图片")
End If
For Each pic In ActiveDocument.InlineShapes
pic.Borders.Enable = True
With pic
For Each aBorder In pic.Borders
With aBorder
.LineWidth = wdLineWidth025pt
.Color = wdColorBlue
End With
Next aBorder
.ScaleHeight = 100
.ScaleWidth = 100
End With
Next
Application.ScreenUpdating = True
End Sub
Sub 取消边框()
Dim a As Integer
a = ActiveDocument.InlineShapes.Count
If a = 0 Then
MsgBox ("没有发现嵌入式图片")
End If
ActiveDocument.InlineShapes(1).Borders.Enable = False
End Sub
Private Sub CommandButton1_Click()
嵌入式图片加边框
End Sub
Private Sub CommandButton2_Click()
取消边框
End Sub
效果如下:
二、Word中如何用VBA 将所有图片加上边框
只要一句代码?那就给你一句参考一下吧:
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)
三、Excel 怎么用VBA代码给表格加上边框
Private Sub CommandButton1_Click()
Dim I, L,J, M
Set SH1 = Sheet1
On Error GoTo QQ
M = InputBox("输入行数!")
If M = "" Then Exit Sub
With SH1
L = .[A1000].End(xlUp).Row
For I = 1 To M
.Cells(I + L, 1) = .Cells(L, 1) + I
For J = 1 To 5
.Cells(I + L, J).BorderAround ColorIndex:=3, Weight:=xlThin '红色、细线
Next
Next
End With
QQ:
End Sub
四、如何用 Word VBA 在任一选定区域插入1*1表格,既用表框起来,另有
这种事情,用录制宏就可以了
录制之前,先选定一个区域
开始录制
把选定区域内容剪切,
在当前位置插入一个表格
把剪切内容粘贴进表格
结束录制
我的 Word 2007 ,录制的结果是这样的
Sub 宏1()
Selection.Cut
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <>; "网格型" Then
.Style = "网格型"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
Selection.PasteAndFormat (wdPasteDefault)
End Sub
五、怎么用vb编程操作word绘制表格的边框
怎么用vb编程操作word绘制表格的边框操作步骤:
1、单击开始----查找按钮(或按Ctrl + F组合键);
2、弹出查找对话框,在查找内容处输入需要查找的数字,在以下项中查找处选择主文档,单击关闭按钮;
3、此时文档中所的查找的数字都被选中。
转载请注明出处51数据库 » vbaword表格边框