Problem: vba code for creating a button to save worksheet as Cell

C

caldog

Public Sub SaveAsA1()

ThisFile = Range("A1").Value

ActiveWorkbook.SaveAs Filename:=ThisFile

End Sub


I have created a button that would save the worksheet as the value in cell A1.
I keep getting an error with the above code. Can someone point out where I
am going wrong , and suggest an alternative way of coding for this cmd.
Thanks,

Steve
 
D

Dave Peterson

What's the value in A1?

If you put the date in there, remember that you can't use slashes in
filenames--at least in Windows.
 
C

caldog

Always the word 'Current' and then a three digit number, with no slashes or
hyphens in it or spaces.

Example: 'Current112'

Steve
 
D

Dave Peterson

Maybe you're looking at the wrong worksheet?

ThisFile = activeworkbook.worksheets("Sheet1").Range("A1").Value

If that doesn't help, maybe you can post the exact error you get.
 
Y

yasser

This is the error message I get:

[ Run-time error '91': Object variable or With block variable not set ]
 
S

Stopher

caldog said:
Public Sub SaveAsA1()

ThisFile = Range("A1").Value

ActiveWorkbook.SaveAs Filename:=ThisFile

End Sub


I have created a button that would save the worksheet as the value in cell A1.
I keep getting an error with the above code. Can someone point out where I
am going wrong , and suggest an alternative way of coding for this cmd.
Thanks,

Steve
Your going to need something like :
Public Sub SaveAsA1()

ThisFile = Range("A1").Value

ActiveWorkbook.SaveAs
with .Filename:=ThisFile
end with
 

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