Help on a save Function

Dangaio

New Member
Joined
Feb 10, 2004
Messages
6
Ok this is the code I have for saving from a cell that contains the file name.. everything works fine up till the point where there is nothing in the cell then it all falls apart.. My question is how do I modify it so when the cell is empty it displays a messagebox and exits the function.. Ok this is wrote as a functon because I have another sub with a VbyesNo code that runs this function upon yes.. It asks as question and depending on the answer it calls the function save2. Any ideas?

[/code]
Function Save2()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim MY_FILE As String
Const ThePath As String = "C:\Inspection Forms\"
If Dir(ThePath) = "" Then MkDir ThePath
MY_FILE = Range("E26").Value
'If MY_FILE = "" Then exit function
ActiveWorkbook.SaveAs Filename:=("C:\Inspection Forms\" & MY_FILE & ".xls"), FileFormat:=xlNormal, _
Password:="password", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
MsgBox "File " & MY_FILE & " Was saved in C:\Inspection Forms", vbInformation, "FILE HAS BEEN SAVED"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Function
Code:
[/b]
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

TommyGun

MrExcel MVP
Joined
Dec 9, 2002
Messages
4,202
Looks like you already have that ready to go. Just uncomment this line.
Code:
'If MY_FILE = "" Then exit function
 

Dangaio

New Member
Joined
Feb 10, 2004
Messages
6
Funny thing is when I do that And the cell is empty I get the error
Run-time error '1004'
Method 'SaveAs' of object "_workbook' failed

But if the cell contains information then it works fine.
 

Dangaio

New Member
Joined
Feb 10, 2004
Messages
6
Ok
If I use this statement with the directory not created I get an error that im unable to access the path

If Dir(ThePath) = "" Then MkDir ThePath

Any Help on this? kinda frustrating.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,489
Messages
5,601,986
Members
414,489
Latest member
Xlambda

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
Top