zxf1218 2017-01-24 06:01 采纳率: 50%
浏览 1928
已采纳

用vb脚本调用saveas将visio文件转换成pdf,应该怎么写?哪位大神帮帮忙

用vb脚本调用saveas将visio文件转换成pdf,应该怎么写?哪位大神帮帮忙

  • 写回答

2条回答 默认 最新

  • 战在春秋 2017-01-31 09:09
    关注

    可以参看如下代码,希望有帮助,因为排版原因,可能还需要你调试一下:

    Option Explicit
    
    Main()
    
    Sub Main()
      If WScript.Arguments.Count > 0 Then 
          Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
          Dim i
          For i = 0 to wscript.arguments.count - 1
              Dim strFilePath : strFilePath = WScript.Arguments.Item(i)
              Dim dirPath : dirPath = objFSO.GetParentFolderName(strFilePath)
              Dim fileBaseName : fileBaseName = objFSO.GetBaseName(strFilePath)
              'WScript.Echo strFilePath
              Dim strNewFileName : strNewFileName = dirPath & "\" & fileBaseName & ".pdf"
              'WScript.Echo strNewFileName
              Dim strFileExt : strFileExt = UCase(objFSO.GetExtensionName(strFilePath))
              Select Case strFileExt
                  Case "DOC"
                      DOC2PDF strFilePath, strNewFileName
                  Case "XLS"
                      XLS2PDF strFilePath, strNewFileName
                  Case "PPT"
                      PPT2PDF strFilePath, strNewFileName
                  Case "VSD"
                      VSD2PDF strFilePath, strNewFileName
                  Case Else
                      WScript.Echo "Extension Type:  " & strFileExt
              End Select
          Next
      Else
          msgbox("some error")
      End If
    End Sub
    
    Sub PPT2PDF(strSourceFile, strDestFile)
      Const ppWindowMinimized = 2
      Const ppWindowNormal = 1
      Const ppSaveAsPDF = 32
    
      Dim objPPT : Set objPPT = CreateObject("PowerPoint.Application")
      objPPT.Visible = True
      objPPT.WindowState = ppWindowMinimized
      objPPT.Presentations.Open strSourceFile
      objPPT.ActivePresentation.SaveAs strDestFile, ppSaveAsPDF 
      objPPT.Quit()
    End Sub
    
    Sub DOC2PDF(strSourceFile, strDestFile)
      Const wdExportAllDocument = 0
      Const wdExportOptimizeForPrint = 0
      Const wdExportDocumentContent = 0
      Const wdExportFormatPDF = 17
      Const wdExportCreateHeadingBookmarks = 1
    
      Dim objWord : Set objWord = CreateObject("Word.Application")
      Dim objDoc : Set objDoc = objWord.Documents.Open(strSourceFile,,TRUE)    
      objWord.ActiveDocument.ExportAsFixedFormat strDestFile, wdExportFormatPDF, False, _
                      wdExportOptimizeForPrint, wdExportAllDocument,,, _
                      wdExportDocumentContent, False, True, wdExportCreateHeadingBookmarks
      objWord.Quit()
    End Sub
    
    Sub XLS2PDF(strSourceFile, strDestFile)
      Const xlTypePDF = 0
    
      Dim objExcel : Set objExcel = CreateObject("Excel.Application")
      Dim objeDoc : Set objeDoc = objExcel.Workbooks.Open(strSourceFile,,TRUE)    
      objExcel.ActiveWorkbook.ExportAsFixedFormat xlTypePDF, strDestFile
      objExcel.ActiveWorkbook.Close(False)
      objExcel.Quit
    End Sub
    
    Sub VSD2PDF(strSourceFile, strDestFile)
      Const xlTypePDF = 1
      Const visOpenRO = 2
      Const visOpenMinimized = 16
      Const visOpenHidden = 64
      Const visOpenMacrosDisabled = 128
      Const visOpenNoWorkspace = 256
    
      Dim objVisio : Set objVisio = CreateObject("Visio.Application")
      Dim objeDoc : Set objeDoc = objVisio.Documents.OpenEx(strSourceFile, visOpenRO + visOpenMinimized + visOpenHidden + visOpenMacrosDisabled + visOpenNoWorkspace)    
      objeDoc.ExportAsFixedFormat xlTypePDF, strDestFile, 1, 0
      objeDoc.Close
      objVisio.Quit
    End Sub
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 数电几道习题,写出作答过程,ai一律不采用
  • ¥15 利用pthon计算薄膜结构的光导纳
  • ¥15 海康hlss视频流怎么播放
  • ¥15 Paddleocr:out of memory error on GPU
  • ¥30 51单片机C语言数码管驱动单片机为AT89C52