PDA

View Full Version : Word, save at first



Francoisch
01-30-2008, 02:14 PM
hello




My other, old, and a Word beginner, forgets quite often to save what she just keyed in in Word.



I would like to install on her PC some VBA code which would:
- be launched at any New document opening
- trigger the Save as little panel to ask for a file name

This should work in these two situations:
- when Word is launched from scratch (its icon, ...)
- when, Word being active, she would ask to start with a New document



I already have this:



Sub AutoNew()
ActiveDocument.Save
EndSub



which copes with the second situation, I believe.


Thank you in advance for your help.



Francois

gwkenny
01-30-2008, 04:31 PM
Hi:

Try the following :D

Sub autoexec()
Documents.Add
ActiveDocument.Save
End Sub

Francoisch
01-31-2008, 01:25 AM
hello and thank you for your answer.

I tried the solution you are proposing and got the same results as with the solution I already had:
- starting from Word icon: perfect, the Save as box opens up nicely
- starting Word with opening an existing Word document: OK but this first starts launching the opening of a New document, which is not asked, before opening the existing document
- starting in Word, already opened, by clicking for New document: nothing

I also tested with the 2 solutions together with the same results.

As a summary, I like the first situation, am embarassed with the second one and am still looking for a solution for the third one.

If anyone around had a solution to handle these situations.

Thank you in advance for your help.

Francois

gwkenny
01-31-2008, 03:39 AM
Francois:

Thank you! Can't believe I never ran into this, but then again, I can understand why :D I learned something and that's always cool.

Okay, Microsoft is always ever so helpful. Here they tell you that they know about the problem:

http://support.microsoft.com/kb/79054

Course, there's no information about what to do. LOL

THE DEFINITIVE answer I got from the following link. You can just follow the instructions I'm going to give you below the link, but I always think it is appropriate to cite sources.

http://www.word.mvps.org/FAQs/MacrosVBA/PseudoAutoMacros.htm

I cut down the code in the above referenced link and programmed it for your needs.

You can either:

A) Download the DOT from my stinky website at the following location:

http://fin-itsolutions.com/Office/Word/

It's the only file in the directory: PseudoAutoNew.dot

I'll leave the file up for a week or so.

Copy this file into your Word startup folder.

Or

B) You can create it on your own:

1) Copy the following into a Module of a new document:

*** code begins here ***
Option Explicit
Dim oAppClass As New ThisApplication
Public oldNoOfOpenDocs As Long
Public FirstNewDoc As Boolean
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
oldNoOfOpenDocs = 0
FirstNewDoc = True
End Sub
*** code ends here ***

2) Copy the following into a class module named: ThisApplication

*** code begins here ***
Option Explicit
Public WithEvents oApp As Word.Application
Private Sub oApp_DocumentChange()
On Error GoTo ExitCode
Dim newNoOfOpenDocs As Long
Dim docAdded As Boolean

newNoOfOpenDocs = Application.Documents.Count

If newNoOfOpenDocs > oldNoOfOpenDocs Then
docAdded = True

If ActiveDocument.Name = "Document1" And FirstNewDoc Then
FirstNewDoc = True
Else
FirstNewDoc = False
End If
oldNoOfOpenDocs = oldNoOfOpenDocs + 1

ElseIf oldNoOfOpenDocs > newNoOfOpenDocs Then
FirstNewDoc = False
oldNoOfOpenDocs = oldNoOfOpenDocs - 1
End If

If docAdded Then
If Len(ActiveDocument.Path) = 0 Then
Call PsuedoAutoNew
End If

ElseIf FirstNewDoc Then
If Len(ActiveDocument.Path) = 0 Then
Call PsuedoAutoNew
End If

End If

Exit Sub

ExitCode:

End Sub
Private Sub PsuedoAutoNew()
ActiveDocument.Save
End Sub
*** code ends here ***

3) Save this new document as a template

4) Move this template to your startup directory

Smile, yer done :D

Heh, one of these days, I'll get my vb to html loaded for Word. hehe


EDIT: Added VBA tags for code - Tommy

Francoisch
01-31-2008, 01:07 PM
hello gwkenny

Thank you very much for your answer, I am really impressed with the huge piece of work you just did to bring a solution to my problem.

I voted myself for the A solution, thus downloading your .DOT file and copying it into the Word folder; to be honest, I would not have been able to find the right places you mentionned, into the B solution, to drop the code into them.

Just to be sure to be right, I dropped it into C:\Program Files\Microsoft Office\Office as well as in C:\Program Files\Microsoft Office\Models since I found a normal.dot into these two folders.

Did I do the right thing?

So far, opening Word or opening a new document from inside Word does not do a thing different from scratch.

Thank you again for your splendid work, sorry in the meantime for not being skilled enough to even install your code properly.

Francois

perhol
01-31-2008, 02:35 PM
In MS Word 2003 startupfolder normally is:
C:\Users\YourUsername\AppData\Roaming\Microsoft\Word\STARTUP

Replace YourUsername with your username.

gwkenny
01-31-2008, 11:19 PM
Depends on your setup.

My default startup folder is:

C:\Documents and Settings\g\Application Data\Microsoft\Word\STARTUP

To find your startup folder, choose the menu: TOOLS/OPTIONS/FILE LOCATION TAB

You should see startup there to your left somewhere and on the right is your directory. You might have to browse and then look at the pull down to get the actual directory. But it's there!!! Just buried!!! lol

Francoisch
02-01-2008, 12:58 AM
hello folks

Good news: Yes, i found with your help my startup folder named here
C:\Documents and Settings\Fran\Application Data\Microsoft\Word\D?MARRAGE; I just didn't know that there was such a folder.

Good news: the Gwkenny .Dot works great, in either situation.

This is exactly what I was looking for; I trust that my mother will never forget to name her files anymore.

Thank you again for your kind help.

Francois

fumei
02-04-2008, 10:10 AM
Just a note.

c:\documents and settings\yaddayadda\.....\STARTUP

will do a startup for THAT username.

C:\Program Files\Microsoft Office\Office10\Startup

will do a startup for ALL users of that machine.

Francoisch
02-04-2008, 11:08 AM
Thank you for your answer.

Yes, I had part of the solution and your answer broaden the cope of it.

Thank you.

Francois