Macro to save Excel file

M

maperalia

I have a macro that saves an Excel file with specific name and path (see
below).
However, sometimes I forget the fill out the information needed like time,
date or hours and the file is been saved without this information.
How can I get a message box to tell me that one or all the range needed have
not been filled?
Thanks in advance.
Maperalia


Sub SaveExcelFile()

Dim Tract As String
Dim WO As String
Dim Supplier As String
Dim Dates As String
Dim Hours As String
Dim sFilename As String


WO = Worksheets("Gradation Form").Range("G2")
Tract = Worksheets("Gradation Form").Range("G3")
Supplier = Worksheets("Gradation Form").Range("C6")
Dates = Worksheets("Gradation Form").Range("G4")
Hours = Worksheets("Gradation Form").Range("G5")


Progname = "C:\Mario\VB\Excel\" & WO & "_" & Tract & "_" & Supplier &
"_" & Dates & "_" & Hours & ".xls"
ActiveWorkbook.SaveCopyAs Progname
End Sub
 
D

Dave Peterson

How about adding something like:

Dim myRngToComplete as range


with worksheets("gradation form")
set myrngtocomplete = .range("G2:G5,C6")
end with

if myrngtocomplete.cells.count <> application.counta(myrngtocomplete) then
msgbox "oh, oh! Cannot save!"
exit sub
end if
 

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