Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

SaveAs error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gerry P - 11 Apr 2007 16:04 GMT
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
old man - 11 Apr 2007 16:58 GMT
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
[quoted text clipped - 8 lines]
> Gerry Pyle
> Columbus, Ohio
Perry - 11 Apr 2007 18:56 GMT
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

> It usually means that the path or one of the folders in the target path
> does
[quoted text clipped - 16 lines]
>> Gerry Pyle
>> Columbus, Ohio
Gerry P - 12 Apr 2007 14:50 GMT
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

Signature

Gerry Pyle
Columbus, Ohio

> In addition:
> How's is this filename built up?
[quoted text clipped - 31 lines]
> >> Gerry Pyle
> >> Columbus, Ohio
Perry - 12 Apr 2007 23:14 GMT
Try to change this
> mask = "ddMMyy"
into

mask = "ddMMyy hhmmss"

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE

> There are no protected files or folders and the filename looks good.
>
[quoted text clipped - 69 lines]
>> >> Gerry Pyle
>> >> Columbus, Ohio
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.