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]
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Looks like you already have that ready to go. Just uncomment this line.
Code:
'If MY_FILE = "" Then exit function
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,239
Members
448,951
Latest member
jennlynn

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