Reputation: 165
I have a question about userforms. Currently I have a forum button set up with a macro that will show the user a userform, where the user will enter data, and then save 5 out of the 6 sheets as a new book. I want to make it so the file name is based off the value of ProjectName (Me.ProjectName.Value), the first field in the userform. Here is what I have so far:
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data List")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a Name number
If Trim(Me.ProjectName.Value) = "" Then
Me.ProjectName.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.ProjectName.Value
ws.Cells(iRow, 2).Value = Me.ProjectNumber.Value
ws.Cells(iRow, 3).Value = Me.SPVComp.Value
ws.Cells(iRow, 4).Value = Me.Contact.Value
ws.Cells(iRow, 5).Value = Me.ProjMan.Value
ws.Cells(iRow, 6).Value = Me.PODate.Value
ws.Cells(iRow, 7).Value = Me.PONumber.Value
ws.Cells(iRow, 8).Value = Me.PRNumber.Value
ws.Cells(iRow, 9).Value = Me.EstTime.Value
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
Sheets(Array("Document Data", "Invoice data", "Hours", "Summary", "Invoice")).Copy
fname = Application.GetSaveAsFilename(Filename:=Me.ProjectName.Value, FileFilter:="Excel Files (*.xlsm), *.xlsm")
ActiveWorkbook.SaveAs Filename:=fname, FileFormat:=52
'clear the data
Me.ProjectName.Value = ""
Me.ProjectNumber.Value = ""
Me.SPVComp.Value = ""
Me.Contact.Value = ""
Me.ProjMan.Value = ""
Me.PODate.Value = ""
Me.PONumber.Value = ""
Me.PRNumber.Value = ""
Me.EstTime.Value = ""
Me.ProjectName.SetFocus
The error I get is name argument not found on Filename:=. I'm still very new to VBA so I'm not exactly sure what to do here. Thank you in advance for the help!
Upvotes: 1
Views: 882