Invalid file name from valid source

corquando

Board Regular
Joined
Jan 8, 2009
Messages
82
Greetings:
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Apologies if this is redundant. It’s half Excel & half Word, so perhaps I’m drifting out of phase a bit here.
<o:p></o:p>
Nonetheless, yesterday this bit of code worked fine:
<o:p></o:p>
DocName = CStr(Workbooks("Production Master").Sheets("OR").Range("A" + CStr(i))) 'define DocName for save
<o:p></o:p>
appWd.ActiveDocument.SaveAs Filename:="C:\Documents and Settings\nwa0tiu\Desktop\NAKA Attachments\" + DocName + ".doc"
<o:p></o:p>
Today, I get:
“Run-time Error 5152
“This is not a valid file name”
<o:p></o:p>
I’ve changed nothing. I set appWd as the object (Word.Application), opened the datasource, cleared the locked fields, set the first record . . .
<o:p></o:p>
Up to this point, it’s a standard mail merge macro. I’m simply retrieving the document name from a worksheet using relevant bits of data; the cell called in the DocName statement is a concatenation of these bits, in text format.
<o:p></o:p>
I copied the SaveAs path directly from the folder’s address box. When I hover the cursor over the variable DocName, I get the memo window displaying the correct name. Removing the ‘CStr’ solves nothing as well.
<o:p></o:p>
I am befuddled. Clues? I’m sure it’s something little and dumb.
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Never Mind.

There's a "/" in the DocName concatenation. Like I said . . . "simple & dumb."

But thanks anyway. I'm sure it would have been found out sooner or later.
 
Upvote 0
Wild guess, having not used macro's with word, try changing + to &
It looks like you should be concatenating not adding.
 
Upvote 0
Howdy - looks like genius struck simultaneously. I discovered the problem at the same time your suggestion came in.

It was something little & dumb like that . . .

But this site is still the best by far for quick and substantial answers.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,892
Members
449,058
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top