Enthusiastic Amateur
New Member
- Joined
- Jul 13, 2023
- Messages
- 1
- Office Version
- 2021
- Platform
- Windows
Hello!
I am trying to create a macro that will combine a string value and a cell value to create a file name (I don't want those pesky end-users giving these files any oddball names).
For bonus points I want the user to define the Save To directory -AND- this is CSV output file and it needs to be converted into an XLSX file.
Here is what I have so far. This allows the user to name the file and choose the directory they wish to save it to:
This works fine and I could stop here, but perfectionism is a blessing & curse.
What I would prefer is to predefine the file name to "Case Log for "[cell value] where cell value = the name of a doctor.
Here is what I have for this:
The ...? is where I'm struggling to find the best solution for this.
How do I best:
1) Combine the two Strings to create a combined file name
2) Save this to a user defined directory
3) Convert the file from a CSV >> XLSX format.
Any advice would be appreciated!
Thanks in advance!
I am trying to create a macro that will combine a string value and a cell value to create a file name (I don't want those pesky end-users giving these files any oddball names).
For bonus points I want the user to define the Save To directory -AND- this is CSV output file and it needs to be converted into an XLSX file.
Here is what I have so far. This allows the user to name the file and choose the directory they wish to save it to:
Excel Formula:
Private Sub SaveFile()
Do
fname = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel Workbook (*.xlsx), *.xlsx")
Loop Until fname <> False
ActiveWorkbook.SaveAs filename:=fname, FileFormat:=xlNormal
End Sub
This works fine and I could stop here, but perfectionism is a blessing & curse.
What I would prefer is to predefine the file name to "Case Log for "[cell value] where cell value = the name of a doctor.
Here is what I have for this:
Excel Formula:
Sub SaveFile2()
Dim MDname As String 'MDName is the Dr's name in cell A2
Dim CaseLogName As String
Range("A2").Select
MDname = ActiveCell.Value
CaseLogName = "Case Log for " & MDname
...?
End Sub
The ...? is where I'm struggling to find the best solution for this.
How do I best:
1) Combine the two Strings to create a combined file name
2) Save this to a user defined directory
3) Convert the file from a CSV >> XLSX format.
Any advice would be appreciated!
Thanks in advance!