Using vba to copy the contents of a word document into another word document

前端 未结 5 1185
谎友^
谎友^ 2020-12-16 22:04

I haven\'t used VB for years, so please forgive me if this turns out to be obvious. I\'m trying to write a word vba macro for use in a template which will display a userform

5条回答
  •  青春惊慌失措
    2020-12-16 22:37

    'set current doc name and path
        Dim docName As String: docName = ActiveDocument.name
        Dim filepath As String: filepath = ActiveDocument.Path
    'create a new file
        Documents.Add
    'get the path of a current file
        ChangeFileOpenDirectory filepath
    'insert content of current file to newly created doc
        Selection.InsertFile _
            FileName:=docName, _
            Range:="", _
            ConfirmConversions:=False, _
            Link:=False, _
            Attachment:=False
    'open prompt to save a new file
        With Dialogs(wdDialogFileSaveAs)
            .name = docName & "-copy"
            .Show
        End With
    

提交回复
热议问题