Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
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 walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

823 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