在 VBA 中将变量值更改为 Proper Case?

Change a variable value to Proper Case in VBA?

我有一个文本框,传统上标记为 TextBox1,我的 TextBox1 只接受大写输入(用于名称),但我使用相同的文本将文件保存在文件夹中,当我保存时我想要名称Title case 中的人是 isnead,但我无法弄清楚如何。

这是我到目前为止得到的(我不知道如何使用字符串,所以如果有一些错误请原谅):

 Private Sub CommandButton1_Click()
 Dim title As String
 title = TextBox1.Value
 Console.WriteLine (StrConv(title, VbStrConv.ProperCase))
 ' Proper Case /\

On Error GoTo Erro1
ChDir "C:\Modelos"
Workbooks.Open Filename:="C:\Modelos\MODELO - PACKING LIST.xlsx"
ChDir "C:\Users\andre.lins\Documents\Processos\Packs"
Tryagain:    ActiveWorkbook.SaveAs Filename:= _
"C:\Users\andre.lins\Documents\Processos\Packs\PKDB\Packing list - " & TextBox1.Value & ".xlsx", FileFormat:= xlOpenXMLWorkbook, CreateBackup:=False



GoTo Errorjump

Erro1:

escape = MsgBox("Qualquer alteração modificará o modelo, por favor, evite modificar o documento. Deseja salvar uma cópia?", vbYesNoCancel, "Atenção")

end sub

您的代码更新应该可以解决问题:

Private Sub CommandButton1_Click()

    Dim title As String
    Dim wrkBk As Workbook

    'As this code sits behind the command button on the form, ME is a reference to the form.
    title = StrConv(Me.TextBox1.Value, vbProperCase)

    'Set a reference to the workbook - code or user interaction may change the activeworkbook.
    Set wrkBk = Workbooks.Open("C:\Modelos\MODELO - PACKING LIST.xlsx")
    wrkBk.SaveAs "C:\Users\andre.lins\Documents\Processos\Packs\PKDB\Packing list - " & title & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

End Sub