• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6992
  • Last Modified:

VBA MS Word - how to save a copy of the current document to a temporary file?

Using VBA withing MS Word (Office 2000 onwards).

I would like to save a temporary copy copy of the current document, which I will later check into Sharepoint 2001 using PKMCDO.

I cannot use:
dim sTempfile as string
sTempFile = "C:/zzz.doc"  'Some example templrary file name
Application.saveas (sTempFile)
because that changes the current document to be name of the temproray file, and maintains a lonk on the document.  I need to save a whole new copy that is avaiable to process using PKMCDO.

Is there a way to do this?  Perhaps using the another instance of the word.application object to instantiate another instance of Word, copying the current word object into that instance and then saving that instance?  Maybe it is much easier than that!

Any help appreciated.
  • 3
2 Solutions
The following macro will copy the current document into a document test.tmp.
Sub Macro24()
    Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
    Selection.PasteAndFormat (wdPasteDefault)
    ActiveDocument.SaveAs FileName:="test.tmp", FileFormat:= _
        wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
        True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
        False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
End Sub
colly92002Author Commented:
Thanks that works.  However I also need to add any other templates that the current document has in the document template - is this possible?
colly92002Author Commented:
I really need to save all  the macros in the "current" document from the template in the "new" document!  
Tommy KinardCommented:
Why not just save it twice?

Sub SaveACopy()
    Dim sTempFile As String
    Dim sHoldFile As String
    sHoldFile = ActiveDocument.Name
    sTempFile = "C:/zzz.doc"
    ActiveDocument.SaveAs (sTempFile)
    ActiveDocument.SaveAs (sHoldFile)
End Sub


colly92002Author Commented:
Thanks - both good ideas!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now