none
Word Macro problem RRS feed

  • 問題

  • 我有一個word檔案, 很長, 很多篇文章都存放一個檔案內, 而且有好多個同類檔案, 上司要我盡快把內類每篇文都抽出來, 獨立save做一個檔案, 錄了個macro, 但係一到 filename saveas的時候就失敗, 請指正:

    Sub Macro4()
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "Document "
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = False
            .MatchFuzzy = False
        End With
        Selection.Find.Execute
        Selection.MoveDown Unit:=wdLine, Count:=1
        Selection.MoveUp Unit:=wdScreen, Count:=16, Extend:=wdExtend
        Selection.Copy
        Documents.Add DocumentType:=wdNewBlankDocument
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "COMMENT "
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = False
            .MatchFuzzy = False
        End With
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.Find.Execute
        Selection.HomeKey Unit:=wdLine
        Selection.MoveDown Unit:=wdLine, Count:=1
        Selection.EndKey Unit:=wdLine, Extend:=wdExtend
        Dim a As String
        Selection.Copy
        a=selection
            ActiveDocument.SaveAs FileName:=a, FileFormat:=wdFormatDocument, LockComments:=False, Password:="", _
            AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
            EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
            :=False, SaveAsAOCELetter:=False
    End Sub

    2008年1月25日 上午 03:20

解答

  • 本文屬於 Office Developer ,將移文至 Office Develop 版。

     

    Code Snippet

    a=selection
            ActiveDocument.SaveAs FileName:=a, FileFormat:=wdFormatDocument, LockComments:=False, Password:="", _
            AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
            EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
            :=False, SaveAsAOCELetter:=False

     

     

    變數 a 為 selection 物件,並非檔名字串。

     

    2008年1月25日 上午 06:37
    版主