2016-03-31 4 views
1

Ich habe ein Textfeld, traditionell als TextBox1, mein TextBox1 akzeptiert nur Großbuchstaben Eingabe (für Namen), aber ich verwende den gleichen Text, um die Datei in einem Ordner zu speichern, wenn ich den Namen der Person speichern möchte im Titel Fall ist nur, aber ich kann nicht herausfinden, wie. HierÄndern Sie einen Variablenwert in Proper Case in VBA?

ist das, was ich habe bisher (ich weiß nicht, wie Zeichenfolgen verwenden, so verzeihen Sie, wenn es etwas werid Fehler ist):

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 

Antwort

2

Dieses Update, um Ihren Code sollte es tun:

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 
+0

Mann, vielen Dank! Du bist der beste! Wenn du wusstest, wie oft ich versucht habe es zu lösen ... Hab einen tollen Tag !!! Du verdienst es (: – ADrex