且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在VBA中将变量值更改为适当大小写吗?

更新时间:2023-02-15 17:37:33

此代码更新可以解决问题:

This update to your code should do the trick:

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