Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

743 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