Solved

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

Posted on 2007-03-20
5
6,199 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now