View Full Version : Solved: Save as & file name\path problem

09-24-2009, 06:47 AM
Hi guys! :hi:

As usual, I've been playing around with this teeny bit of code for a while now and have hit a wall. :banghead:

I fix one part, just to have another complain....and I know it's not even a complex bit of code!! :bug:

At present it's complaining that the save as method has failed, although this worked until a few moments ago. :doh:

Could I ask one of you gentlemen to have a look and see where todays screw up has arrived from?

In short, this is supposed to:
1. select the appropriate sheet
2. copy it to it's own workbook
3. save it to a specific file path & a file name designated by cell C4
4. print itself out
5. open an e-mail dialog box and attach the file
6. politely close the copy spreadsheet before returning you to the original workbook.

Simple enough...or so I thought... :(

Any guidance, wisdom or otherwise support would be greatly welcomed :bow:

Phel x

PS - This is an old workbook that someone else built and I'm trying to make fit a new process. I know that it's a really awful way of doing this, but it's what I've got to work with!!

Private Sub Command Button 1_Click()
Dim fname As String

Sheets("4series - fees").Select
Sheets("4series - fees").Copy
fname = "C:\Services\People" & "\" & Range("C4").Value
ActiveWorkbook.SaveAs Filename:=fname
Windows("automated forms 2008.xls").Activate
Sheets("INPUT SHEET").Select

End sub

Bob Phillips
09-24-2009, 07:34 AM
What is in C4?

09-24-2009, 07:41 AM
A client name, simply text. Is that where the problem is?

Bob Phillips
09-24-2009, 07:46 AM
I don't know, it may have invalid characters or some control character. Just a thought.

09-24-2009, 07:55 AM
I've altered the code slightly to see what was coming through as fname and am just getting "C:\services\clients\" so it's not picking up the range command. There is a formula there, but it's being told to copy the value...ich bin confused!

Dim fname As String
Sheets("4series - fees").Select
Sheets("4series - fees").Copy
fname = "C:\Services\People" & "\" & Range("C4").Value
MsgBox (fname)

'ActiveWorkbook.SaveAs Filename:=fname
'Windows("automated forms 2008.xls").Activate
'Sheets("INPUT SHEET").Select

Bob Phillips
09-24-2009, 07:57 AM
Qualify the range with the sheet name, you are probably picking up C4 from the wrong sheet.

09-24-2009, 08:40 AM
Strangely seemed to work as soon as I made it a module rather than a worksheet connected macro...it's predecessor was set up on the sheet rather than a stand alone module, so I simply cannibalised it.

I've put in several sheet("X").select 's to ensure that the right sheet is being used. But it works as intended now.

Glad to know that it wasn't a complete failing of code on my part! Just a failing of logic! :yes

Thank you for your help, got me thinking on the right track!! :beerchug:

Phel x