Creating a macro from a non-saved Word doc that duplicates the current open document and saves it
Hi,
I'm very, very new to VBA and am trying to create a macro that will duplicate all of the contents (including comments, markup, etc.) of an open document (that will most likely not have been saved on the computer as it will be opened directly from Sharepoint) and save it to the local computer (i.e. in Documents), and then close it, leaving the original document open. This is one macro that I want to occur before a set of other macros that clean up the document--I'm essentially trying to save the original one for backup purposes, so the additional clean-up macros should only be applied to the original opened document, not the newly duplicated one.
I've searched around and have tried out a bunch of different codes with no luck. The current code that's gotten my the closest prompts the 'Save' dialogue, and I'm able to save it but then when I try to open it I get an error telling me it cannot be found. This is the current code I'm using:
Sub Macro1()
' Macro1 Macro
Const lCancelled_c As Long = 0
Dim sSaveAsPath As String
sSaveAsPath = GetSaveAsPath
If VBA.LenB(sSaveAsPath) = lCancelled_c Then Exit Sub
'Save changes to original document
ActiveDocument.Save
'the next line copies the active document
Application.Documents.Add ActiveDocument.FullName
'the next line saves the copy to your location and name
ActiveDocument.saveAs "C:\Users\name\Documents"
'next line closes the copy leaving you with the original document
ActiveDocument.Close
End Sub
I've also tried this one (via the Record function) and there seems to be an error in the bold line.This is copied from a larger macro so the sub/end macros aren't included:
'CopyDoc Macro
Selection.WholeStory
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdUseDestinationStylesRecovery)
ActiveDocument.Save
ActiveDocument.SaveAs2 FileName:="StoryPackCopy123.docx", FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=15
Windows("CRM Story Pack Phase 2").Activate
Any and all help would be appreciated!
|