0

从标题复制文件名后,我在 MS word 中有一个宏来重命名文件。

我记录了宏,但是当我保存并粘贴文件名(Ctrl + V)时,宏正在对文件名进行硬编码。相反,我想从存储了文件名的剪贴板中复制内容。

请帮助我根据需要更改代码。

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.MoveDown Unit:=wdLine, count:=2
    Selection.EndKey Unit:=wdLine
    Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
    Selection.Copy
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.EscapeKey
    ChangeFileOpenDirectory "C:\Documents and Settings\ssankees\Desktop\"
    ActiveDocument.SaveAs2 FileName:= _
        "KP27 Display Plan Data for Activity Types.doc", FileFormat:= _
        wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
        True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
        False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=0
4

1 回答 1

1

如果你想保存你正在处理的文件,试试这个:

Dim DataObj As New MSForms.DataObject
DataObj.GetFromClipboard
Dim my_filename as String 

my_filename = DataObj.GetText

ActiveDocument.SaveAs2 FileName:= _
    my_filename, FileFormat:= _
    wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
    True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
    False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
    SaveAsAOCELetter:=False, CompatibilityMode:=0
于 2013-08-07T11:26:47.290 回答