[英]Macro works in Word 2013, but not in 2010
我想為我的同事創建一個模板,並創建一個“將另存為..”到特定文件的宏,並使用標題來建議名稱。
宏以某種方式忽略目標位置,並打開標准的“文檔”文件夾
這要靠下面的代碼解決!
Sub FileSave() ' ' FileSave Macro ' Het actieve document of de actieve sjabloon opslaan ' ChangeFileOpenDirectory _ "F:\Company\Marketing\Voorstellen\Voorstellen\Voorstel\" If ActiveDocument.Path = "" Then ' If the document has never been saved, the ' value of its .Path is an empty string; otherwise ' it has the file's path and name. With Dialogs(wdDialogFileSaveAs) .Name = MakeDocName ' call the function below .Show ' the suggested name will be in the dialog End With Else ' The document has already been saved with a name ' so just save it there. ActiveDocument.Save End If End Sub Function MakeDocName() As String Dim theName As String Trim(ActiveDocument.BuiltInDocumentProperties("Title")) MakeDocName = theName ' return the assembled name End Function
刪除(\\)backslash
theName = "F:\Company\Marketing\Voorstellen\Voorstellen\Voorstel\"
至
theName = "F:\Company\Marketing\Voorstellen\Voorstellen\Voorstel"
^'suggested Name = Voorstel
我剛剛刪除了MakeDocName函數的所有非操作部分,這在Word 2010中對我來說效果很好(還請注意Title屬性中的大寫字母T:
Function MakeDocName() As String
Dim theName As String
theName = "C:\00_Projects_temp\" & Trim(ActiveDocument.BuiltInDocumentProperties("Title"))
MakeDocName = theName ' return the assembled name
End Function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.