How do I determine if it is a new file or an existing file?

C

Conan Kelly

How can I tell (via VBA code) if the workbook is a new workbook from a
template or an existing workbook?

If it is a new workbook, I want to SaveAs and give it a name. If it is an
existing file, I just want to save it.

I already understand the SaveAs and Save methods. I just don't know how to
check whether it is new or existing.

Thanks for any help anyone can provide,

Conan Kelly
 
R

Ron de Bruin

Hi Conan

A workbook that is not saved one time have no path so you can test it like this.

Sub test()
If ActiveWorkbook.Path = "" Then
MsgBox "New workbook"
Else
MsgBox "Old workbook"
End If
End Sub
 
G

Guest

try this

sub checknew()
if workbooks("namehere").path = "" then
'workbook is new
else
'workbook is not new
end if
end sub
 

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