Solved

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

Posted on 2007-03-20
5
6,531 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:colly92002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 14

Accepted Solution

by:
Glenn_Moore earned 65 total points
ID: 18756379
The following macro will copy the current document into a document test.tmp.
Sub Macro24()
    Selection.WholeStory
    Selection.Copy
    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, _
        SaveAsAOCELetter:=False
End Sub
Glenn
0
 
LVL 15

Author Comment

by:colly92002
ID: 18757831
Thanks that works.  However I also need to add any other templates that the current document has in the document template - is this possible?
0
 
LVL 15

Author Comment

by:colly92002
ID: 18843815
I really need to save all  the macros in the "current" document from the template in the "new" document!  
0
 
LVL 14

Assisted Solution

by:Tommy Kinard
Tommy Kinard earned 60 total points
ID: 18846513
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

HTH
dragontooth

0
 
LVL 15

Author Comment

by:colly92002
ID: 18850913
Thanks - both good ideas!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Suggested Courses
Course of the Month6 days, 21 hours left to enroll

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question