PDA

View Full Version : COPY UNSAVED DOCUMENT



qazpl
05-31-2008, 11:39 PM
I am trying to create exact copy of open unsaved document. SaveAs is no good - original loses changes. Vesion.Save is no good - changes can't be undone and document is saved. Clipboard copy and paste will not be exact if document differs. Is it possible to create new doc based on existing doc. All I need is conceptual help, I can write the VBA. THANKS IN ADVANCE

lucas
06-01-2008, 10:07 AM
Is it possible to create new doc based on existing doc.

Sounds like a job for a template. Save your file that you want to copy as a .dot or template file....when you run the .dot file a clone is created and it doesn't affect your template.....am I missing something?

qazpl
06-01-2008, 11:58 AM
THANKS FOR YOUR REPLY. Let me clarify. I CAN NOT save users document or remove ability to undo changes with my addin, that would not always be in users best interest. What I need is mirrored document with edits created by addin. For example if I want to create document that has all misspelled words underlined so that it is visable when printed I wouldn't want to change users document to generate new document. Saving unsaved document as template would lose current changes to doc unless doc is saved which I can't do. THANKS

lucas
06-01-2008, 03:41 PM
So you are receiving a document from someone and you want to open it and make changes and mark errors and then make a copy with your changes saved to the copy but not to the original document?


Assuming that is correct I would suggest that you make a copy of it before you start and change the name and make your changes......seems like the easiest way.

If you want to use code you can try running this on the open document after you make your changes......

to be clear....open the users document and make your changes and then run this code. When you try to close the original document it will ask if you want to save changes....just say no.

Option Explicit
Sub SaveAs()
Const lCancelled_c As Long = 0
Dim sSaveAsPath As String
sSaveAsPath = GetSaveAsPath
If VBA.LenB(sSaveAsPath) = lCancelled_c Then Exit Sub
'Save changes to original document
' ActiveDocument.Save
'the next line copies the active document
Application.Documents.Add ActiveDocument.FullName
'the next line saves the copy to your location and name
ActiveDocument.SaveAs sSaveAsPath
'next line closes the copy leaving you with the original document
ActiveDocument.Close
End Sub
Public Function GetSaveAsPath() As String
Dim fd As Office.FileDialog
Set fd = Word.Application.FileDialog(msoFileDialogSaveAs)
fd.InitialFileName = ActiveDocument.Name
If fd.Show Then GetSaveAsPath = fd.SelectedItems(1)
End Function

lucas
06-01-2008, 03:43 PM
The code above will not work on an unsaved file.

qazpl
06-01-2008, 07:55 PM
I am writing word addin (actually in c++ ATL) and don't want to put restriction when this option is available which is why I am trying to work with unsaved document. THANKS LUCAS. I figure that you guys have the deepest knowledge of WORD, but in word app doesn't seem possible. THANKS AGAIN

lucas
06-01-2008, 08:41 PM
Sorry, I don't know of a way to accomplish this.

fumei
06-02-2008, 11:27 AM
I am still trying to follow what is wanted. I have no idea what:

"Clipboard copy and paste will not be exact if document differs. "

means. Huh?

You have an unsaved document. OK. That means it is a document created from a template (Normal or otherwise).

If you copy it to another unsaved document...then you have copied it. This is easy. Both are unsaved. And...now what?

I am not following. There seems to be talk about looking at a users document. If you are doing that, then it can not be unsaved.

I am not following.

"why I am trying to work with unsaved document"

HOW are you even getting this unsaved document?????

qazpl
06-02-2008, 01:02 PM
Thanks Fumei for your interest I was hoping you would pitch in since you have helped me in the past. My addin is installed on users computer. One of the features of addin is underlining all words that are misspelled so that mistakes are tagged when doc is printed. I don't want to change original document so I need a copy of document in its current state upon which I will make my changes. The problem with copy and paste is that there are many other factors effecting the appearance of the doc. for example columns, doc size, margins, style defenitions etc. which is not duplicated. THANKS AGAIN and looking forward to your reply.

fumei
06-02-2008, 02:37 PM
Sorry, but you are still not being clear.

"The problem with copy and paste is that there are many other factors effecting the appearance of the doc. for example columns, doc size, margins, style defenitions etc. which is not duplicated."

This is simply not true. You can make an absolute copy, including those - except for style definitions. Although you can copy the style. All properties of the active document can be detected (if needed) and a new document have those values. You could make a new blank document from the template the original was cloned from. You could copy the range and use wdFormatOriginalFormatting. All sorts of things.

"upon which I will make my changes."

WHAT changes?????

"underlining all words that are misspelled so that mistakes are tagged when doc is printed"

Why on earth would you want to print a document with mistakes visible??

And you still have not answered the question about some unsaved document. WHAT unsaved document?

If you have a user document...then it is NOT unsaved. Therefore you can do a SaveAs and work on that one.

Sorry, but I am still not following what you are trying to do.