-1
我有一點詞彙vba代碼來簡化我的工作流程。其中的一部分是安全的模板文件到子文件夾結構深處的特定文件位置。vba word wdDialogFileSaveAs不保存
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格式保存一個預期的文件,但這個詞一個不...我已經嘗試了一些不同的選項,並使用手動保存爲提示的錯誤...兼容性的東西。
辛迪,感謝的工作!它有點奇怪的構造,但我到了那裏。 – user2815681
是的,Word對話框背後的功能可追溯到20年前的舊WordBasic日子。所以他們絕對是怪獸! –