|
我在网上找到的word vba,想拿来用用,但是执行的过程中出现了编译错误,语法错误。
Private Sub CommandButton12_Click()
Setduixiang = CreateObject("Shell.Application") '创建一个对象
Setwenjianjia = duixiang.BrowseForFolder(0, "", 0, "") '选择word文档所在的文件夹
If Not wenjianjia Is Nothing Then
wenjianlujing = wenjianjia.Items.Item.path '获取所选择的文件夹的路
End If
yuanwenjian = Dir(wenjianlujing & "\" & "*.doc") '获取所选择word文档的文件名
Setdakaiwenjian = Documents.Open(wenjianlujing & "\" & yuanwenjian) '打开选择的word文档
yegao = dakaiwenjian.PageSetup.PageHeight 'word文档高度
yekuan = dakaiwenjian.PageSetup.PageWidth 'word文档宽度
zuobianju = dakaiwenjian.PageSetup.LeftMargin 'word文档左边距
dingbianju = dakaiwenjian.PageSetup.TopMargin 'word文档顶边距
MkDir Left(wenjianlujing & "\" & yuanwenjian, Len(wenjianlujing & "\" & yuanwenjian) - 4) '在word文档所在的文件夹新建与word文档同名的文件夹
yemashu = Selection.Information(wdNumberOfPagesInDocument) '获得所打开的word文档的页码数
Selection.HomeKey wdStory '将光标移至当前内容的开始
For n = 1 To yemashu
kaishi = Selection.Range.Start '当前页开始字符数
If n = yemashu Then '如果是最后一页
zhongzhi = ActiveDocument.Content.End '最后一页的终止字符数
Else
zhongzhi = Selection.GoToNext(wdGoToPage).End '当前页的终止字符数
Selection.GoToPrevious wdGoToPage '将光标移至当前页文字部分的开始
End If
ActiveDocument.Range(kaishi, zhongzhi).Copy '复制word文档当前页的所有对象[3, 7] ………………
SetkongbaiPPT = huandeng.Slides.Add(n, 12) '新建一张空白PPT
With duixiang2.ActivePresentation.PageSetup
.SlideWidth = yekuan
.SlideHeight = yegao
End With '设置为与所打开的word文档尺寸同样的尺寸
Set zhantieneirong = duixiang2.ActiveWindow.View.Slide
With zhantieneirong
Set weizhi = .Shapes.PasteSpecial(2)
weizhi.Left = zuobianju: weizhi.Top = dingbianju
End With '在新建空白PPT上粘贴,并将所粘贴内容的页边距设置为与所打开的word文档同样的页边距 [3,4]
With duixiang2.ActivePresentation.Slides(n).Export Left(wenjianlujing & "\" & yuanwenjian, Len(wenjianlujing & "\" & yuanwenjian) - 4)& "\" & n &".jpg", "JPG", ScaleWidth:=yekuan * 3, ScaleHeight:=yegao * 3
End With '在新建的文件夹中输出jpg文件并按顺序逐幅命名
Selection.GoToNextwdGoToPage '将光标移至所打开word文档的下一页内容的开始
End Sub
应该是红色部分出现了错误,请老师给看看,帮帮我。
|
|