Adicionado em: | 31/10/2011 |
Modificado em: | 31/10/2011 |
Tamanho: | Vazio |
Downloads: | 1134 |
Esses macros e procedimentos do Aplicativo Microsoft Excel VBA(Visual Basic Application), usando o Evento Worksheet_Change, afeta a folha de planilha ativa ao digitar algo, neste caso escolhemos duas células (B5 e D5), ao digitar nestas células determinadas palavras o aplicativo abrirá um
userform com algumas textbox vai inserir dados em determinadas colunas na folha de planilha.
Espero que o exemplo lhe seja útil. Fique com Deus, Expedito Marcondes.
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
INSIRA O CÓDIGO ABAIXO NA FOLHA DE CÓDIGO DA FOLHA DE PLANILHA
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$5" And Target.Count = 1 Then
If Target.Value = "Motor" Then
frmDADOS1.Show
End If
ElseIf Targett.Address = "$D$5" And Target.Count = 1 Then
If Target.Value = "Ponte" Then
frmDADOS2.Show
End If
End If
End Sub
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NO MODULO DE EDIÇÃO DO FORMULÁRIO frmDADOS1 INSIRA OS CÓDIGOS:
Private Sub cmdLANCAR_Click()
[O6:P1000].ClearContents 'limpar a area de inserção de novos dados.
Plan1.[O65000].End(xlUp).Offset(1, 0) = "Largura"
Plan1.[O65000].End(xlUp).Offset(0, 1) = CDbl(txtLARGURA)
Plan1.[O65000].End(xlUp).Offset(1, 0) = "Comprimento.:"
Plan1.[O65000].End(xlUp).Offset(0, 1) = CDbl(txtCOMPRIMENTO)
MsgBox ("Dados inseridos com sucesso"), vbInformation, "Saberexcel - o site das macros"
End Sub
Private Sub cmdFECHAR_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
txtLARGURA.SetFocus
End Sub
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NO MODULO DE EDIÇÃO DO FORMULÁRIO frmDADOS2 INSIRA OS CÓDIGOS:
Private Sub cmdLANCAR_Click()
[J6:K1000].ClearContents
Plan1.[J65000].End(xlUp).Offset(1, 0) = "Potencia"
Plan1.[J65000].End(xlUp).Offset(0, 1) = CDbl(txtPOTENCIA)
Plan1.[J65000].End(xlUp).Offset(1, 0) = "Tensão"
Plan1.[J65000].End(xlUp).Offset(0, 1) = CDbl(txtTENSAO)
Plan1.[J65000].End(xlUp).Offset(1, 0) = "Rotação"
Plan1.[J65000].End(xlUp).Offset(0, 1) = CDbl(txtROTACAO)
MsgBox ("Dados inseridos com sucesso"), vbInformation, "Saberexcel - o site das macros"
End Sub
Private Sub UserForm_Initialize()
txtPOTENCIA.SetFocus
End Sub
Private Sub cmdFECHAR_Click()
Unload Me
End Sub
Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Escola Saberexcel VBA Estudos® - Treinamentos com Macros, Fórmulas e Funções.
Adicionado em: | 01/11/2011 |
Modificado em: | 01/11/2011 |
Tamanho: | Vazio |
Downloads: | 818 |
Saberexcel- o site de quem precisa aprender Macros MS Excel VBA
Esses procedimentos do aplicativo Microsoft Excel VBA(Visual Basic Application), usando objetos textboxes, retorna a quantidade de textboxes
preenchidos, com uma operação matematica.
Private Sub cmdCONTAR_Click()
Dim vContador, iValor
ObjetosTxt = 10
iValor = 0
For vContador = 1 To ObjetosTxt
If Len(Me.Controls("cmbTEXTO" & vContador)) > 0 Then
iValor = iValor + 1
End If
Next
'uma mensagem com quebra de linhas -- intuito didático.
MsgBox "Neste formulário há: " & vbCrLf & _
"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" & vbCrLf & _
"[ " & iValor & _
" ] .....: - TextBox's preenchidos " & vbCrLf & "[ " & ObjetosTxt - iValor & _
" ] .....: - TextBox's Vazios " & vbCrLf & _
"[ " & Val(ObjetosTxt) & " ] .....: - TextBox's no Total" & _
vbCrLf & "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" & _
vbCrLf & "Escola Saberexcel VBA Estudos® - Treinamentos" & _
vbCrLf & "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -", _
vbInformation, "Saberexcel VBA Estudos®"
End Sub
Private Sub cmdFECHAR_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Me.cmbTEXTO1.SetFocus
End Sub
Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim Resposta As String
Resposta = MsgBox("deseja conectar com nosso site ?", vbYesNo + vbQuestion, "Saberexcel - site das macros")
If Resposta = vbYes Then
ThisWorkbook.FollowHyperlink "http://www.microsoftexcel.com.br/", , True
End If
End Sub
Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Escola Saberexcel VBA Estudos® - Treinamentos com Macros, Fórmulas e Funções.
Adicionado em: | 03/11/2011 |
Modificado em: | 03/11/2011 |
Tamanho: | Vazio |
Downloads: | 1066 |
Saberexcel - o site de quem precisa aprender macros ms Excel VBA
Esses procedimentos do Aplicativo Microsoft Excel VBA(Visual Basic Application), com declarações retiram o cabeçalho do formulário.
Private Sub UserForm_Initialize()
Label2.Visible = False
RETIRAR_CABECALHO_SABEREXCEL Me.Caption, False
End Sub
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Const GWL_STYLE = (-16)
Const WS_CAPTION = &HC00000
Const SWP_FRAMECHANGED = &H20
Public Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Sub RETIRAR_CABECALHO_SABEREXCEL(stCaption As String, sbxVisible As Boolean)
Dim vrWin As RECT
Dim style As Long
Dim lHwnd As Long
lHwnd = FindWindowA(vbNullString, stCaption)
GetWindowRect lHwnd, vrWin
style = GetWindowLong(lHwnd, GWL_STYLE)
If sbxVisible Then
SetWindowLong lHwnd, GWL_STYLE, style Or WS_CAPTION
Else
SetWindowLong lHwnd, GWL_STYLE, style And Not WS_CAPTION
End If
SetWindowPos lHwnd, 0, vrWin.Left, vrWin.Top, vrWin.Right - vrWin.Left, _
vrWin.Bottom - vrWin.Top, SWP_FRAMECHANGED
End Sub
Sub abrir_form()
frmSaber.Show
End Sub
Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Escola Saberexcel VBA Estudos® - Treinamentos com Macros, Fórmulas e Funções.
Adicionado em: | 10/11/2011 |
Modificado em: | 10/11/2011 |
Tamanho: | Vazio |
Downloads: | 1814 |
Saberexcel - O site de quem precisa aprender Macros Microsoft Excel VBA.
Esses procedimentos do Aplicativo Microsoft Excel VBA, cadastra dados em determinada folha de Planilha, por meio de objetos textboxes.
' - - - - - - - - - - - - - - - -
Private Sub cmdLANCAMENTO_Click()
Dim vPALAVRA As Long
vPALAVRA = Plan1.Range("A65536").End(xlUp).Row + 1 'localiza a última linha +1 (célula vazia)
'poderá criar um verifica inconsistência para todos os ítens abaixo.
If txtNOME = "" Then
MsgBox ("Preencha os dados corretamente")
Exit Sub
End If
'observe a simplicidade do código, localiza as ultimas linha/colunas e grava dados
'Plan1 - é o nome da folha de código da folha de planilha, se o usuário mudar o nome da folha de planilha na aba,
'não ocorrerá erro, porque referenciamos o nome da folha de código da folha de planilha.
Plan1.Range("a" & vPALAVRA).Value = Me.txtNOME.Text
Plan1.Range("b" & vPALAVRA).Value = Me.txtENDERECO.Text
Plan1.Range("c" & vPALAVRA).Value = Me.txtBAIRRO.Text
Plan1.Range("d" & vPALAVRA).Value = Me.txtCIDADE.Text
Plan1.Range("e" & vPALAVRA).Value = Me.cboESTADO.Text
Plan1.Range("f" & vPALAVRA).Value = Me.txtCEP.Text
Plan1.Range("g" & vPALAVRA).Value = Me.txtTELEFONE.Text
Plan1.Range("h" & vPALAVRA).Value = Me.txtOBSERVACAO.Text
MsgBox ("Dados inseridos com sucesso"),vbInformation, "http://www.microsoftexcel.com.br"
lblCONTADOR.Caption = vPALAVRA 'mostrando o próximo codigo cliente, cada gravação
'limpando as TextBox depois de ter gravado os dados na folha de planilha
Me.txtNOME.Value = ""
Me.txtENDERECO.Value = ""
Me.txtBAIRRO.Value = ""
Me.txtCIDADE.Value = ""
Me.txtCIDADE.Value = ""
Me.cboESTADO.Value = ""
Me.txtCEP.Value = ""
Me.txtTELEFONE.Value = ""
Me.txtOBSERVACAO.Value = ""
Me.txtNOME.SetFocus 'retornando o cursor para o TextBox (txtNOME)
End Sub
' - - - - - - - - - - - - - - - -
'carregar a combobox com os estados ao inicializar, isto é ao abrir o formulário.
Private Sub UserForm_Initialize()
vPALAVRA = Plan1.Range("A65536").End(xlUp).Row + 1 ' numerar o proximo cadastro
lblCONTADOR.Caption = vPALAVRA
cboESTADO.List = Array("AC", "AL", "AP", "AM", "BA", "CE", "DF", "GO", "MA", "MG", "MT", _
"MS", "PA", "PB", "PR", "PE", "PI", "RJ", "RS", "RN", "RD", "SC", "SP", "SE", "TO")
End Sub
' - - - - - - - - - - - - - - - -
'fechar o formulário na conclusão das tarefas
Private Sub cmbSAIR_Click()
Unload Me
End Sub
' - - - - - - - - - - - - - - - -
'esse procedimento determina a localização de abertura do formulário na folha de planilha
Private Sub UserForm_Activate()
With frmCADASTRO
.Top = Application.Top + 149
.Left = Application.Left + 30
End With
End Sub
' - - - - - - - - - - - - - - - -
Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Escola Saberexcel VBA Estudos® - Treinamentos com Macros, Fórmulas e Funções.
Adicionado em: | 13/11/2011 |
Modificado em: | 13/11/2011 |
Tamanho: | Vazio |
Downloads: | 699 |
Saberexcel - o site de quem precisa aprender macros MS Excel VBA
Esses macros usando a instrução Select Case, chama determinada macro de acordo com o nome atribuido ao botão renomeado(Shapes),
objeto botão da barra de formulario do Aplicativo do Excel
Sub sbx_botao_clique()
[D:D].ClearContents
Select Case Application.Caller
Case "btnUM"
MsgBox ("Botão 1 - Numeros Pares"), vbInformation, "Escola Saberexcel VBA Estudos®"
sbx_inserir_autonumeracao_pares
Case "btnDOIS"
MsgBox ("Botão DOIS - Numeros Impares"), vbInformation, "Escola Saberexcel VBA Estudos®"
sbx_inserir_autonumeracao_impares
End Select
End Sub
Sub sbx_inserir_autonumeracao_pares()
vLinha = 0
[D:D].ClearContents
For vLinha = 0 To 20
[d45000].End(xlUp).Offset(1, 0).Value = vLinha
vLinha = vLinha + 1
Next
End Sub
Sub sbx_inserir_autonumeracao_impares()
vLinha = 1
[D:D].ClearContents
For vLinha = [F1].Value To 20 Step 1
[d45000].End(xlUp).Offset(1, 0).Value = vLinha
vLinha = vLinha + 1
Next
End Sub
Sub sbx_limpar_teste()
[D:D].ClearContents
[G1].Select
End Sub
Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Escola Saberexcel VBA Estudos® - Treinamentos com Macros, Fórmulas e Funções.
Adquira já o Acesso Imediato
à Area de Membros
Aprenda Excel VBA com Simplicidade de
códigos e Eficácia, Escrevendo Menos e
Fazendo Mais.
'-------------------------------------'
Entrega Imediata:
+ 500 Video Aulas MS Excel VBA
+ 35.000 Planilhas Excel e VBA
+ Coleção 25.000 Macros MS Excel VBA
+ 141 Planilhas Instruções Loops
+ 341 Planilhas WorksheetFunctions(VBA)
+ 04 Módulos Como Fazer Excel VBA
+ Curso Completo MS Excel VBA
+ Planilhas Inteligentes
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2317234650173689";
/* retangulo 336 x 280 */
google_ad_slot = "0315083363";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Aprenda tudo sobre o Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Saberexcel,
Sobre as WorksheetFunctions Funções de Planilhas que retornam valores do VBA