ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 841|回复: 2

[求助] 求助利用vba批量将同一目录下的viso文件为pdf

[复制链接]

TA的精华主题

TA的得分主题

发表于 2020-2-27 20:56 | 显示全部楼层 |阅读模式


代码运行不通过,麻烦高手修正。谢谢

Sub 批量将VISIO文件转成PDF()
    Dim str As String, n As Long, Nam As String
    Set VisioApp = GetObject(, "Visio.Application")
    On Error GoTo err '程序出错时则退出
   ' Dim fd As Object
  '  Set fd = Application.FileDialog(msoFileDialogFolderPicker)

    Dim Filename$, myPath$, dPath$              '文件名,路径
    Dim thesh As Object
    Dim thefolder As Object


    Set thesh = CreateObject("shell.application")
    Set thefolder = thesh.BrowseForFolder(0, "", 0, "")
       myPath = thefolder.Items.Item.Path
        myPath = myPath & Application.PathSeparator


        Dim Fp As String
        Fp = myPath & "PDF"   '新建文件夹全路径名
        If Dir(Fp, vbDirectory) = "" Then
          MkDir Fp
        Else

    End If
        dPath = myPath & Application.PathSeparator & Fp

    Application.DisplayAlerts = False
    Application.ScreenUpdating = False  '关闭屏幕更新,提升速度
    str = Dir(myPath & "\*.VSD*")  '开始查找文件,格式为所有vsd和vsdx文件
    While Len(str) > 0
        n = n + 1  '累加变量,该变量代表文件数量

        MsgBox (myPath & str)
        MsgBox (dPath)
        VisioApp.Documents.Open myPath & str
        VisioApp.ActiveDocument.ExportAsFixedFormat visFixedFormatPDF, myPath & str, 1, 0
        VisioApp.ActiveDocument.Close
        str = Dir()  '查找下一个
    Wend
    Application.ScreenUpdating = True  '恢复屏幕更新
err:
End Sub



TA的精华主题

TA的得分主题

 楼主| 发表于 2020-2-27 22:19 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-2-27 23:41 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
新代码还是通过不了,打开了visio文件转换不了为pdf,麻烦各位帮忙修正,谢谢

Sub ss()
'vsd转pdf

On Error Resume Next
Const xlTypePDF = 1
Const visOpenRO = 2
Const visOpenMinimized = 16
Const visOpenHidden = 64
Const visOpenMacrosDisabled = 128
Const visOpenNoWorkspace = 256
Dim sEveryFile As String, sSourcePath As String, sNewSavePath As String
Dim objVisio  As Object
Set objVisio = CreateObject("Visio.Application")
Dim CurXls As Object
sSourcePath = "E:\2222\"
'假定待转换的xlsx文件全部在"E:\visio文件\"下,你需要按实际情况修改。
sEveryFile = Dir(sSourcePath & "*.vsd")
Do While sEveryFile <> ""
Set CurXls = objVisio.Documents.OpenEx(sSourcePath & sEveryFile, visOpenRO + visOpenMinimized + visOpenHidden + visOpenMacrosDisabled + visOpenNoWorkspace)
'Set CurXls = Documents.Open(sSourcePath & sEveryFile)
sNewSavePath = VBA.Strings.Replace(sSourcePath & sEveryFile, "*.vsd", ".pdf")
   '转化后的文件也在"E:\xlsx文件\"下,当然你可以按需修改。
CurXls.ActiveDocument.ExportAsFixedFormat xlTypePDF, sNewSavePath, 1, 0
   '更多格式可参见文末的截图ExportAsFixedFormat
CurXls.ActiveDocument.Close SaveChanges:=False
CurXls.ActiveDocument.Quit
sEveryFile = Dir
Loop
Set CurXls = Nothing

End Sub
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-27 08:57 , Processed in 0.038996 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表