Easy one: What to name this

klarowe

Active Member
Joined
Mar 28, 2011
Messages
389
I just wrote this quick code for saving some new reports I'm making up and it runs great if I don't have "Option Explicit" but if I add it in, it brings up an error. I know its because I don't have "Dim SaveName as ____" but I can't seem to find anything to fill in the blank with that works. Where am I going wrong?
Rich (BB code):
Sub SaveAs()
    On Error GoTo Err
    SaveName = Sheets("Home").Range("C38").Value
    MkDir "\\TBISUSFS001\Share\SERVICE\Repair Shop Build Books\" & SaveName
    ActiveWorkbook.SaveAs Filename:= _
        "\\TBISUSFS001\Share\SERVICE\Repair Shop Build Books\" & SaveName & "\" & SaveName
Err: MsgBox "File was not saved.", vbOKOnly, "File Not Saved"
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi klarowe,

Think about what SaveName is holding. If the value in C38 is always a number, then try using Long. If the value is always a string, or a mixture, then try String.

If all else fails, you can always use Variant - although I don't recommend this but for such a small piece of code you will be fine.
 
Upvote 0
I thought about long, but its a mix of letters / numbers. I also tried Variant and it didn't seem to work (gave me an error). I'll try string.... didn't even think of that one.

Edit: String seemed to have worked. Thanks for the help!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,461
Messages
6,055,561
Members
444,799
Latest member
CraigCrowhurst

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