在VBA中将变量值更改为适当大小写吗? [英] Change a variable value to Proper Case in VBA?

查看:75
本文介绍了在VBA中将变量值更改为适当大小写吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,传统上标记为TextBox1,我的TextBox1仅接受大写输入(用于名称),但是我使用相同的文本将文件保存在文件夹中,所以当我保存时,我想要该人的名字在标题情况下不算老大,但我不知道怎么做.

I have a textbox, traditionally labeled as TextBox1, my TextBox1 accepts only Uppercase input (for names), but i'm using the same text to save the file in a folder, when i save i want the name of the person to be in Title case isntead, but I cant figure out how.

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

Here is what i got so far (i dont know how to use strings, so pardon if there is some werid mistake):

 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

推荐答案

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

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

这篇关于在VBA中将变量值更改为适当大小写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆