Trouble with Save As macro

L

Logan

I'm having two problems with this Save As macro

Sub Save_As()
Dim FName1, FName2, FName3, Fullname
FName1 = "CK0"
FName2 = Range("AU2").Value & "-"
FName3 = Range("J4").Value
Fullname = FName1 & FName2 & FName3
Application.DisplayAlerts = False
ChDir "G:\New"
ActiveWorkbook.SaveAs Fullname, FileFormat _
:=xlNormal, CreateBackup:=False
MsgBox "Saved to " & CurDir
End Sub


Problem one is that the ChDir command won't force it to go
to the 'G' drive it saves it in My Documents. I've gone
into Tools/Options and change the default setting to 'G'
and that works, but I didn't think I should have to do
that, I thought the CHDir command would do that for me.

The second problem is that I placed a custom macro command
on my toolbar to run the macro. Problem is when I try to
use it, it says with the name"The last file name I just
saved" is already open.
It seems like it is recalling the last saved document.
If I just go tools macro and run it that way it works fine.

Any ideas??
 
H

Harald Staff

Part 1 answer: Sure. Procedure goes:

ChDrive "G:\New"
ChDir "G:\New"

HTH. Best wishes Harald
 
S

Stuart

Try
ChDrive "G"
before
ChDir

Regards.

Logan said:
I'm having two problems with this Save As macro

Sub Save_As()
Dim FName1, FName2, FName3, Fullname
FName1 = "CK0"
FName2 = Range("AU2").Value & "-"
FName3 = Range("J4").Value
Fullname = FName1 & FName2 & FName3
Application.DisplayAlerts = False
ChDir "G:\New"
ActiveWorkbook.SaveAs Fullname, FileFormat _
:=xlNormal, CreateBackup:=False
MsgBox "Saved to " & CurDir
End Sub


Problem one is that the ChDir command won't force it to go
to the 'G' drive it saves it in My Documents. I've gone
into Tools/Options and change the default setting to 'G'
and that works, but I didn't think I should have to do
that, I thought the CHDir command would do that for me.

The second problem is that I placed a custom macro command
on my toolbar to run the macro. Problem is when I try to
use it, it says with the name"The last file name I just
saved" is already open.
It seems like it is recalling the last saved document.
If I just go tools macro and run it that way it works fine.

Any ideas??
 
F

Frank Kabel

Hi Logan
1. Question:
try
ChDrive "G:"
ChDir "G:\New"

2. Are you invoking this f´rom multiple sheets?. You may change
Range(..)
to
ActiveSheet.Range(..)
or
AvtiveWorkbook.ActiveSheet.range(...)
 
D

Dick Kusleika

Logan

You also might consider not changing the current drive or directory, unless
you need to for some other reason

ActiveWorkbook.SaveAs "G:\New\" & Fullname, etc..
 
L

Logan

Thanks, I will try the suggestions at the end of next week.
On vacation now...
Will post with update

Thanks for the imput
 
L

Logan

I couldn't get the command to work from the toolbar, so I
formatted a command button on the sheet that seems to work.

The toolbar command seems to stay with the the last sheet.
When I use it to save the workbook, close Excel, re-open
the workbook template, and view the macro assigned to it,
it's the last file saved (C:/NewFile.......)

Any ideas?

I would rather run the macro from the toolbar rather than
from a command button on my sheet, if possible



-----Original Message-----
 

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