Formato Hora em Com...
 
Notifications
Clear all

Formato Hora em Combobox

4 Posts
3 Usuários
0 Reactions
1,826 Visualizações
(@caio-abreu)
Posts: 0
New Member
Topic starter
 

Bom dia pessoal,

Estou criando um formulário de agenda no qual eu incluo uma data (Já fiz este processo) e um horário já predefinido numa combobox (9h, 9:30, 10h, 10:30, etc)

Quando eu seleciono um horário destes que eu defini, o arquivo salva normalmente o horário que selecionei (depois de muito tempo tratando isso), porém, no próprio formulário, quando seleciono um horário da lista, a cmbbox preenche este horário em formato número no formulário.

Ou seja, apesar de estar acontecendo isso, o resultado final está normal, porém no formulário está feio, pois a lista aparece os horários normal, mas quando seleciono um, o preenchimento vem em formato número.

Sei que há uma função no VBA Format... Mas não estou conseguindo aplicar.

Alguém pode me ajudar?

Obrigado!

 
Postado : 08/03/2017 7:57 am
(@hronconi)
Posts: 314
Reputable Member
 

Dim MyTime, MyDate, MyStr
MyTime = #17:04:23#
MyDate = #January 27, 1993#

' Returns current system time in the system-defined long time format.
MyStr = Format(Time, "Long Time")

' Returns current system date in the system-defined long date format.
MyStr = Format(Date, "Long Date")

MyStr = Format(MyTime, "h:m:s") ' Returns "17:4:23".
MyStr = Format(MyTime, "hh:mm:ss AMPM") ' Returns "05:04:23 PM".
MyStr = Format(MyDate, "dddd, mmm d yyyy") ' Returns "Wednesday,
' Jan 27 1993".
' If format is not supplied, a string is returned.
MyStr = Format(23) ' Returns "23".

' User-defined formats.
MyStr = Format(5459.4, "##,##0.00") ' Returns "5,459.40".
MyStr = Format(334.9, "###0.00") ' Returns "334.90".
MyStr = Format(5, "0.00%") ' Returns "500.00%".
MyStr = Format("HELLO", "<") ' Returns "hello".
MyStr = Format("This is it", ">") ' Returns "THIS IS IT".

 
Postado : 08/03/2017 8:22 am
(@caio-abreu)
Posts: 0
New Member
Topic starter
 

Muito obrigado!

No meu caso que é combobox, eu aplico qual dessas variáveis e em que momento?

Segue o cósigo do meu botão "Salvar":

Private Sub CmdSalvar_Click()

Planilha1.Range("F3").Select

Do

If Not (IsEmpty(ActiveCell)) Then
ActiveCell.Offset(1, 0).Select

End If

Loop Until IsEmpty(ActiveCell) = True

EnumeraLista

ActiveCell.Offset(0, 1).Value = TxtCalendário.Text
ActiveCell.Offset(0, 2).Value = CmbHorário.Text
ActiveCell.Offset(0, 3).Value = CmbRecorrência.Text
ActiveCell.Offset(0, 4).Value = TxtResponsável.Text
ActiveCell.Offset(0, 5).Value = TxtCompromisso.Text

LimparCampos

ActiveWorkbook.Save

MsgBox "Compromisso marcado com sucesso", vbInformation, "Agenda"

End Sub

 
Postado : 08/03/2017 11:22 am
(@syrax)
Posts: 0
New Member
 

Use o código

format(variável, "hh:mm:ss")

Sendo variável, o valor que voce pretende formatar

se isso te ajudou, clique no joinha ao lado de "citar"

 
Postado : 10/03/2017 7:53 pm