【问题标题】:vba word wdDialogFileSaveAs doesn't savevba word wdDialogFileSaveAs 不保存
【发布时间】:2015-11-03 11:36:13
【问题描述】:

我有一些 word vba 代码来简化我的工作流程。其中一部分是安全的模板文件到子文件夹结构深处的特定文件位置。

Function saveFile(fileType As String)
    Dim strFileName As String
    Dim StrPath As String
    Dim instance As WdSaveFormat
    Dim format As String

    'provide a file type
    format = fileType

    'provide default filename
    docname = ActiveDocument.Tables(1).cell(2, 1).Range.Text
    saveName = Left(docname, Len(docname) - 2)

    'provide a path
    projectnumber = ActiveDocument.Tables(1).cell(11, 3).Range.Text
    projectnum = Left(projectnumber, Len(projectnumber) - 2)
    projecttop = Left(projectnumber, Len(projectnumber) - 4)
    pathFull = "H:\Projecten\P0" & projecttop & "00 - P0" & projecttop & "99\P0" & projectnum & "\2 - Bedrijfsbureau\2.Berekeningen\2.2 Berekeningen voorlopig\"

    'provide a revision
    If ActiveDocument.Tables(2).cell(2, 2).Range.Text = Chr(13) & Chr(7) Then
        MsgBox ("Er is niets ingevult?")
    ElseIf ActiveDocument.Tables(2).cell(3, 2).Range.Text = Chr(13) & Chr(7) Then
        revLet = ""
    ElseIf ActiveDocument.Tables(2).cell(4, 2).Range.Text = Chr(13) & Chr(7) Then
        revLet = "_A"
    ElseIf ActiveDocument.Tables(2).cell(5, 2).Range.Text = Chr(13) & Chr(7) Then
        revLet = "_B"
    ElseIf ActiveDocument.Tables(2).cell(6, 2).Range.Text = Chr(13) & Chr(7) Then
        revLet = "_C"
    Else
        revLet = "_D"
    End If

    'concat path
    StrPath = pathFull & saveName & revLet

    With Dialogs(wdDialogFileSaveAs)
        .Name = StrPath
        .format = format
        If .Display <> 0 Then
            strFileName = .Name
        Else
            strFileName = "User Cancelled"
        End If
    End With
End Function

and calling the funcion

    Private Sub CommandButton19_Click()
    'wdFormatXMLDocument => docx wdFormatDocument => doc wdFormatPDF => pdf
    Call saveFile(wdFormatXMLDocumentMacroEnabled)
End Sub

Private Sub CommandButton20_Click()
    'wdFormatXMLDocument => docx wdFormatDocument => doc wdFormatPDF => pdf
    Call saveFile(wdFormatPDF)
End Sub

pdf 的文件按预期保存文件,但单词 one 没有...我尝试了一些不同的选项并手动使用另存为提示错误...具有兼容性的东西。

【问题讨论】:

    标签: vba pdf ms-word


    【解决方案1】:

    我真的很惊讶保存为 PDF 作品...您使用 .Display 将对话框呈现给用户。 Display will NOT EXECUTE 用户选择的对话框操作:如果他单击 Save,则不会执行该命令。显示只显示对话框,用户操作将改变对话框状态。可以在事后读取状态,并且需要您自己的代码进行保存。

    如果您希望对话框执行用户选择的操作,您需要使用 .Show 方法:If .Show Then...

    【讨论】:

    • 辛迪,谢谢你的工作!这是一个奇怪的结构,但我到了那里。
    • 是的,Word 对话框背后的功能可以追溯到大约 20 年前的旧 WordBasic 时代。所以他们绝对是奇怪的野兽!
    猜你喜欢
    • 1970-01-01
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多