ActiveDocument.SaveAS

D

Debi

I'm using Office 2000, Win98.

I've developed a UserForm and trying write the code to
save it before it closes. The code I've written is:

ActiveDocument.SaveAs ("C:\WINDOWS\Desktop\Debi & ' " &
strLastSave & " " & strFirstSave & " " & strDateSave
& " ' "), wdFormatDocument

I've double checked this Path several times but I keep
getting this error message:

"Run-time error 5152

"This is not a valid File name
Try one or more of the following:

*Check the path to make sure it is typed correctly.
*Select a File from the list of Files and Folders."

I've copied and pasted the path from Window's Explorer, so
I know the path is correct.

I can do this in Visual Basic 6.0 and I know that VBA is
not quite like VB6.0, but could someone help me code a
SaveAs?

I greatly appreciate the time and effort put into any help
you give.

Debi
 
J

JGM

Hi Debi,

Just a long shot....

Have you tried:
("C:\WINDOWS\Desktop\Debi\" & strLastSave & " " _
& strFirstSave & " " & strDateSave)

I do this all the time and I have never had any problems with this syntax...
I am confused by yours.... the way it is written it means the both
apostrophes, both a leading and a trailing space and the first ampersand (&)
will be part of the name. Something like:
[ & ' strLastSave strFirstSave strDateSave ' .doc]
(At least, that is the result I got when I pasted your code in Word, just to
make sure!

Also, make sure that your stings do not contain any illegal characters. I
see a variable called "strDateSave" which leads me to think that it might
contain a "/" or a ":".

By the way, I do not know if "strLastSave" has a "\" at the beginning, if it
does, remove the one I put after Debi... or is Debi part of the file name?

HTH
Cheers!
 
G

Guest

Actually, I had not tried that, so I did.....ERROR!! Red
Code line! LOL, so I put it back the way I had it. But
thanks for the effort.

Debi
-----Original Message-----
Hi Debi,

Just a long shot....

Have you tried:
("C:\WINDOWS\Desktop\Debi\" & strLastSave & " " _
& strFirstSave & " " & strDateSave)

I do this all the time and I have never had any problems with this syntax...
I am confused by yours.... the way it is written it means the both
apostrophes, both a leading and a trailing space and the first ampersand (&)
will be part of the name. Something like:
[ & ' strLastSave strFirstSave strDateSave ' .doc]
(At least, that is the result I got when I pasted your code in Word, just to
make sure!

Also, make sure that your stings do not contain any illegal characters. I
see a variable called "strDateSave" which leads me to think that it might
contain a "/" or a ":".

By the way, I do not know if "strLastSave" has a "\" at the beginning, if it
does, remove the one I put after Debi... or is Debi part of the file name?

HTH
Cheers!
--
_______________________________________
Jean-Guy Marcil
(e-mail address removed)

"Debi" <[email protected]> a écrit dans le message de
I'm using Office 2000, Win98.

I've developed a UserForm and trying write the code to
save it before it closes. The code I've written is:

ActiveDocument.SaveAs ("C:\WINDOWS\Desktop\Debi & ' " &
strLastSave & " " & strFirstSave & " " & strDateSave
& " ' "), wdFormatDocument

I've double checked this Path several times but I keep
getting this error message:

"Run-time error 5152

"This is not a valid File name
Try one or more of the following:

*Check the path to make sure it is typed correctly.
*Select a File from the list of Files and Folders."

I've copied and pasted the path from Window's Explorer, so
I know the path is correct.

I can do this in Visual Basic 6.0 and I know that VBA is
not quite like VB6.0, but could someone help me code a
SaveAs?

I greatly appreciate the time and effort put into any help
you give.

Debi


.
 
J

Jonathan West

Hi Debi

It looks very much like you have an extra & character you don't need,
following the word "Debi". Try this (should all be on one line of course)

ActiveDocument.SaveAs ("C:\WINDOWS\Desktop\Debi ' " &
strLastSave & " " & strFirstSave & " " & strDateSave
& " ' "), wdFormatDocument

If that still doesn't work, try adding this line just before the saveAs
line, so you can see what filename the macro is trying to use. (again, put
that all on one line)

MsgBox "C:\WINDOWS\Desktop\Debi & ' " &
strLastSave & " " & strFirstSave & " " & strDateSave
& " ' "

I suspect you know what the path *should* be, but are making some kind of
mistake in adding the various elements of the string together.
 
D

Debi

Jonathan,
I tried both suggestions. The SaveAs suggestion still
returned the same error, and the MsgBox showed the strings
holding the correct information.

Thank you for your time and effort.

Debi
 
D

Debi

Thanks for all your help! I have figured this out
finally ! A couple of things were going on. First, I was
testing my code in "Design" time meaning it was the Actual
Template that was filling not a Document. When the SaveAs
code was correct, I got an error telling me I could not
save a Template in a different format.

I also forgot to format the strSaveDate. So here is the
final code that Works!!!

ActiveDocument.SaveAs ("C:\WINDOWS\Desktop\Debi\" &
strLastSave & Chr(32) & strFirstSave & Chr(32) & Format
(strDateSave, "mm-dd-yy")), wdFormatDocument

I then backed out of Word and opened from the Template
itself. This opened Document1 and I was able to SaveAs
with no problems.

I got some help also from a WordVBA Group that I belong to
in Yahoo Groups. They suggested removing the " " and
replacing with the Chr(32). They said sometimes so
many "Characters" confuse the compiler. It did the trick!!

Thank you again for the time and effort you've spent
helping me.

Debi
 

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