SaveAs error

G

Gerry P

When a macro I have tries via
ActiveDocument.SaveAs FileName:=DocName
I am getting a run-time error 5152, This is not a valid filename.

I have checked the variable DocName and it is a perfectly valid filename.

Any ideas on what's going on here?

Thanks,

Gerry Pyle
Columbus, Ohio
 
O

old man

It usually means that the path or one of the folders in the target path does
not exist. Also it could mean you are trying to overwrite a write protected
word file.

Old man
 
P

Perry

In addition:
How's is this filename built up?
Show us the code in which [DocName] is composed.

Does it contain invalid characters?
\/:;*?"<>|'`,{}[]

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
G

Gerry P

There are no protected files or folders and the filename looks good.

I got this code because I want to save a mail merge document to to separate
files.

Gary Mayor had some nifty code for doing this, but it always stops at the
..SaveAs command.

Sample code below:

Dim mask As String
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
mask = "ddMMyy"

Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
DocName = "D:\My Documents\Temp\Workgroup\" & Format(Date, mask) _
& " " & LTrim$(Str$(Counter)) & ".doc"
ActiveDocument.Sections.First.Range.Cut
Documents.Add ("ranksheet.dot")
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With

//the problem is in this line
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatDocument

ActiveWindow.Close
Counter = Counter + 1
Wend

--
Gerry Pyle
Columbus, Ohio


Perry said:
In addition:
How's is this filename built up?
Show us the code in which [DocName] is composed.

Does it contain invalid characters?
\/:;*?"<>|'`,{}[]

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE



old man said:
It usually means that the path or one of the folders in the target path
does
not exist. Also it could mean you are trying to overwrite a write
protected
word file.

Old man
 
P

Perry

Try to change this
mask = "ddMMyy"
into

mask = "ddMMyy hhmmss"

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE



Gerry P said:
There are no protected files or folders and the filename looks good.

I got this code because I want to save a mail merge document to to
separate
files.

Gary Mayor had some nifty code for doing this, but it always stops at the
.SaveAs command.

Sample code below:

Dim mask As String
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
mask = "ddMMyy"

Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
DocName = "D:\My Documents\Temp\Workgroup\" & Format(Date, mask) _
& " " & LTrim$(Str$(Counter)) & ".doc"
ActiveDocument.Sections.First.Range.Cut
Documents.Add ("ranksheet.dot")
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With

//the problem is in this line
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatDocument

ActiveWindow.Close
Counter = Counter + 1
Wend

--
Gerry Pyle
Columbus, Ohio


Perry said:
In addition:
How's is this filename built up?
Show us the code in which [DocName] is composed.

Does it contain invalid characters?
\/:;*?"<>|'`,{}[]

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE



old man said:
It usually means that the path or one of the folders in the target path
does
not exist. Also it could mean you are trying to overwrite a write
protected
word file.

Old man

:

When a macro I have tries via
ActiveDocument.SaveAs FileName:=DocName
I am getting a run-time error 5152, This is not a valid filename.

I have checked the variable DocName and it is a perfectly valid
filename.

Any ideas on what's going on here?

Thanks,

Gerry Pyle
Columbus, Ohio
 

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