word vba 转换html,[转载]一些WORD VBA代码(替换页眉页脚、批量设置格式

Sub Macro1()

ActiveDocument.Tables(1).Cell(3, 1).Select

Selection.InlineShapes.AddPicture FileName:="C:a.jpg",

LinkToFile:=True, SaveWithDocument:=True

End Sub

HF

Private  Sub  Command1_Click()

Dim  xApp  As  New  Word.Application

Dim  xDoc  As  Document

Dim  xShape  As  InlineShape

Set  xApp  =

New  Word.Application

'添加文档并返回文档对象

Set  xDoc  =

xApp.Documents.Add

'插入一个图形Shape并返回其对象引用

Set  xShape  =  xDoc.InlineShapes.AddPicture( "D:2003

documentMy  Pictures1_151_115.jpg ")

'设置Shape的大小

xShape.Width  =

200

xShape.Height  =

200

Set  xShape  =  Nothing

'保存

xDoc.SaveAs  "c:dfgh.doc

"

xDoc.Close

xApp.Quit

Set  xDoc  =

Nothing

Set  xApp  =

Nothing

End  Sub

这是上面代码的注释,可能对你的理解有一些帮助。如果需要多次插入图片,重复调用

'插入一个图形Shape并返回其对象引用

Set  xShape  =  xDoc.InlineShapes.AddPicture( "D:2003

documentMy  Pictures1_151_115.jpg ")

'设置Shape的大小

xShape.Width  =

200

xShape.Height  =

200

Set  xShape  =  Nothing

就可以了。

'*****************************

哈哈~终于可以了 O YEAH~ 感谢wangz的耐心介绍!另外我找到了另外一种方式,互联网的资源~分享如下:

word批量修改图片大小——固定长宽篇

这部分要说的是把word中的所有图片修改成固定的并且相同的长和宽!

1、打开word,工具-宏-宏(或者直接按Alt+F8)进入宏的界面,如下面所示,输入一个宏名,宏名自己起,能记住就行!

2、宏名起好了,单击“创建”进入Visual Basic 编辑器,输入如下代码并保存

Sub setpicsize() '设置图片大小Dim n'图片个数

On Error Resume Next

'忽略错误

For n = 1

To

ActiveDocument.InlineShapes.Count 'InlineShapes类型图片ActiveDocument.InlineShapes(n).Height

= 400 '设置图片高度为

400px

ActiveDocument.InlineShapes(n).Width = 300 '设置图片宽度 300px

Next

n

For n = 1 To ActiveDocument.Shapes.Count

'Shapes类型图片

ActiveDocument.Shapes(n).Height = 400 '设置图片高度为 400px

ActiveDocument.Shapes(n).Width = 300 '设置图片宽度 300px

Next n

End

Sub

3、返回word,工具-宏-宏(或者直接按Alt+F8),再次进入宏的界面,选择刚才编辑好的宏,并单击“运行”按钮,就可以了!(图片多时,可能会花一些时间)word批量修改图片大小——按比例缩放篇

这部分要说的是把word中的所有图片按比例缩放!

具体操作同上,只是代码部分稍做修改,代码如下:

Sub setpicsize() '设置图片大小Dim n'图片个数Dim picwidth

Dim

picheight

On Error Resume Next

'忽略错误

For n = 1 To ActiveDocument.InlineShapes.Count

'InlineShapes类型图片

picheight = ActiveDocument.InlineShapes(n).Height

picwidth = ActiveDocument.InlineShapes(n).Width

ActiveDocument.InlineShapes(n).Height = picheight * 1.1

'设置高度为1.1倍ActiveDocument.InlineShapes(n).Width

= picwidth * 1.1 '设置宽度为1.1倍

Next n

For n = 1 To

ActiveDocument.Shapes.Count 'Shapes类型图片

picheight = ActiveDocument.Shapes(n).Height

picwidth = ActiveDocument.Shapes(n).Width

ActiveDocument.Shapes(n).Height = picheight * 1.1 '设置高度为1.1倍

ActiveDocument.Shapes(n).Width = picwidth * 1.1 '设置宽度为1.1倍Next nEnd Sub

'********************************

今天收获很大,又找到了批量给图片加边框的方法,分享一下:

Dim i As Integer

For i = 1 To ActiveDocument.InlineShapes.Count

With ActiveDocument.InlineShapes(i)

With .Borders(wdBorderLeft)

.LineStyle = wdLineStyleSingle

.LineWidth = wdLineWidth100pt

.Color = wdColorAutomatic

End With

With .Borders(wdBorderRight)

.LineStyle = wdLineStyleSingle

.LineWidth = wdLineWidth100pt

.Color = wdColorAutomatic

End With

With .Borders(wdBorderTop)

.LineStyle = wdLineStyleSingle

.LineWidth = wdLineWidth100pt

.Color = wdColorAutomatic

End With

With .Borders(wdBorderBottom)

.LineStyle = wdLineStyleSingle

.LineWidth = wdLineWidth100pt

.Color = wdColorAutomatic

End With

.Borders.Shadow = False

End With

With Options

.DefaultBorderLineStyle = wdLineStyleSingle

.DefaultBorderLineWidth = wdLineWidth100pt

.DefaultBorderColor = wdColorAutomatic

End With

Next i

End sub

'****************************

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值