Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-17-2017, 12:12 PM
mike0215 mike0215 is offline Creating a macro from a non-saved Word doc that duplicates the current open document and saves it Windows 10 Creating a macro from a non-saved Word doc that duplicates the current open document and saves it Office 2016
Novice
Creating a macro from a non-saved Word doc that duplicates the current open document and saves it
 
Join Date: Nov 2017
Posts: 4
mike0215 is on a distinguished road
Post 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!
Reply With Quote
 

Tags
copy, save document, word vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
My Word 10 won't open it's own saved files because it says they are corrupted Dave Young Word 5 11-05-2016 09:13 PM
Some images not saved when creating PDF from Word with Acrobat WaltR Word 5 09-26-2015 02:58 PM
Creating a macro from a non-saved Word doc that duplicates the current open document and saves it Word 2003 document saves as Wordpad docx Rick K Word 2 05-06-2015 08:25 AM
Creating a macro from a non-saved Word doc that duplicates the current open document and saves it Cannot open saved Word document otherlunds Word 1 09-01-2014 05:41 AM
Creating a macro from a non-saved Word doc that duplicates the current open document and saves it Run-time error '1004': Document not saved. The document may be open... doctor_who12 Excel Programming 1 01-22-2014 04:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft