Save Document oddity

G

Graham Mayor

I have used macros similar to the following to insert (in this instance) the
path at the foot of a document. However testing this in Word 2007 has thrown
up an anomaly in that the check for whether the document is saved is
completely ignored inevitably causing an error at the line pPathname= if the
document has not already been saved.

This always worked in Word 2003, however on testing again in Word 2003 (my
PC currently has both Word 2003 and 2007 installed in parallel) it no longer
worked there either.

Following a reboot, it worked again in 2003, but not in 2007, and then on
closing 2007 and reopening 2003 it no longer works there. Reboot and open
2007 without first opening 2003 and it still doesn't work :(

Initially I thought that the presence of both versions was the problem, but
my laptop only has 2007 and it doesn't work there either. Any ideas?

I am trying to like 2007 ..... honest .... but it seems to throw up one
problem after another.

On an entirely different note my laptop's Word 2007 has an AddIns tab on the
Ribbon, that of my desktop doesn't. My desktop has Acrobat 8.1 instead. I
guess that may be getting in the way, in the inimitable manner Adobe has of
screwing with Word :( ?

Sub InsrtPath()
Dim pPathname As String
Dim pFoldername As String
With ActiveDocument
If Not .Saved Then
.Save
End If
pPathname = Left$(.FullName, (Len(.FullName) - Len(.Name) - 1))
pFoldername = Right$(pPathname, (Len(pPathname) -
InStrRev(pPathname, "\")))
End With
Selection.TypeText pPathname
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

Testing further
Sub Saved()
If ActiveDocument.Saved = False Then _
MsgBox ("Not Saved")
If ActiveDocument.Saved = True Then _
MsgBox ("Saved")
End Sub
always shows 'Saved' here and if I run 2007 before 2003 it always shows
Saved there too. If I reboot, Word 2003 alone responds correctly?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

While I am still talking to myself, I have found a workaround

If Len(.Path) = 0 Then
.Save
End If

for the saved test,
(and before anyone comments I do know about .path for the original macro -
it was just part of an example)

but I am still puzzled by the original failure.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jeff Mathewson

What it sounds like is depending on what version of Word you are opening
first, the VB object for that version is loading in memory and sticking.
Being on my first cup of coffee here I can't help, but you may need to
manually init the VB object. In VB Editor check to see what references are
loaded.

Jeff
OJD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top