Inquiridor
Macro - Ingles - Portugues

Pergunta
-
Prezados,
Escrevi a macro abaixo no excel 2003 em Ingles. Ela copia e cola como valores os dados de uma planilha baseada em um cubo olap. Após a cópia, ela substituiu os totais e subtotais por contas (=sum.....) fazendo com que as alterações na planilha mudem o valor dos totais e subtotais.
Alguns de nossos usuário usam o Excel 2003 Portugues, e nessas máquinas, a fórmula "=sum..." não funciona, ela deveria ser substituida para "=soma...". Além disso temos um problema de datatype mismatch.
Como posso fazer para que a macro fique independente da versão do excel 2003? Para inglês ou portugues, preciso que a mesma planilha do excel seja usada.
Att.,
Miguel Salles
Code SnippetSub Move_Conteudo()
'
' Move_Conteudo Macro
' Macro recorded 6/14/2007 by jprisco
'
'
Range("A3:O500").Select
Selection.Copy
Sheets("Input-Sheet").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("C5").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[12])"
Range("C5").Select
Selection.Copy
ActiveWindow.SmallScroll ToRight:=-2
Range("C5:C16").Select
Range(Selection, Selection.End(xlDown)).Select
'Range("C5:C500").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("D5").Select
'=================
'Subtotais
'=================
'declara as variavel
Dim iCount
Dim iCount2
Dim iLoop
Dim strName As Variant
Dim cellValue
Dim StrTotGer
Dim MeiaFormula As Variant
Dim QtdSubtotal
'Escolhe a planilha correta
Sheet4.Select
cellValue = Range("B5").Value
strName = cellValue
inicio = 5
iCount = Sheet4.Range("D5", Sheet4.Range("D500").End(xlUp)).Rows.Count
For iLoop = 5 To iCount + 5
'entro em um grupo
If Range("A" & iLoop).Value = "" Then
'entro no subgrupo
If Range("A" & iLoop - 1).Value = "" Then
fim = iLoop
'uma vez para o total mais 1 para cada mes
Range("D" & inicio + 1).Select
ActiveCell.Formula = "=SUM(D" & inicio + 1 & ":D" & fim - 1 & ")"
Range("E" & inicio + 1).Select
ActiveCell.Formula = "=SUM(E" & inicio + 1 & ":E" & fim - 1 & ")"
Range("F" & inicio + 1).Select
ActiveCell.Formula = "=SUM(F" & inicio + 1 & ":F" & fim - 1 & ")"
Range("G" & inicio + 1).Select
ActiveCell.Formula = "=SUM(G" & inicio + 1 & ":G" & fim - 1 & ")"
Range("H" & inicio + 1).Select
ActiveCell.Formula = "=SUM(H" & inicio + 1 & ":H" & fim - 1 & ")"
Range("I" & inicio + 1).Select
ActiveCell.Formula = "=SUM(I" & inicio + 1 & ":I" & fim - 1 & ")"
Range("J" & inicio + 1).Select
ActiveCell.Formula = "=SUM(J" & inicio + 1 & ":J" & fim - 1 & ")"
Range("K" & inicio + 1).Select
ActiveCell.Formula = "=SUM(K" & inicio + 1 & ":K" & fim - 1 & ")"
Range("L" & inicio + 1).Select
ActiveCell.Formula = "=SUM(L" & inicio + 1 & ":L" & fim - 1 & ")"
Range("M" & inicio + 1).Select
ActiveCell.Formula = "=SUM(M" & inicio + 1 & ":M" & fim - 1 & ")"
Range("N" & inicio + 1).Select
ActiveCell.Formula = "=SUM(N" & inicio + 1 & ":N" & fim - 1 & ")"
Range("O" & inicio + 1).Select
ActiveCell.Formula = "=SUM(O" & inicio + 1 & ":O" & fim - 1 & ")"
'esse pedaço jah eh genérico
Range("A" & inicio).Select
ActiveCell.Formula = "Subtotal"
cellValue = Range("D" & iLoop).Value
strName = cellValue
inicio = iLoop
Else
fim = iLoop
Range("D" & inicio).Select
ActiveCell.Formula = "=SUM(D" & inicio + 1 & ":D" & fim - 1 & ")"
Range("E" & inicio).Select
ActiveCell.Formula = "=SUM(E" & inicio + 1 & ":E" & fim - 1 & ")"
Range("F" & inicio).Select
ActiveCell.Formula = "=SUM(F" & inicio + 1 & ":F" & fim - 1 & ")"
Range("G" & inicio).Select
ActiveCell.Formula = "=SUM(G" & inicio + 1 & ":G" & fim - 1 & ")"
Range("H" & inicio).Select
ActiveCell.Formula = "=SUM(H" & inicio + 1 & ":H" & fim - 1 & ")"
Range("I" & inicio).Select
ActiveCell.Formula = "=SUM(I" & inicio + 1 & ":I" & fim - 1 & ")"
Range("J" & inicio).Select
ActiveCell.Formula = "=SUM(J" & inicio + 1 & ":J" & fim - 1 & ")"
Range("K" & inicio).Select
ActiveCell.Formula = "=SUM(K" & inicio + 1 & ":K" & fim - 1 & ")"
Range("L" & inicio).Select
ActiveCell.Formula = "=SUM(L" & inicio + 1 & ":L" & fim - 1 & ")"
Range("M" & inicio).Select
ActiveCell.Formula = "=SUM(M" & inicio + 1 & ":M" & fim - 1 & ")"
Range("N" & inicio).Select
ActiveCell.Formula = "=SUM(N" & inicio + 1 & ":N" & fim - 1 & ")"
Range("O" & inicio).Select
ActiveCell.Formula = "=SUM(O" & inicio + 1 & ":O" & fim - 1 & ")"
Range("A" & inicio).Select
ActiveCell.Formula = "Subtotal"
cellValue = Range("D" & iLoop).Value
strName = cellValue
inicio = iLoop
End If
End If
Next iLoop
'marca os total
For iloop2 = 5 To iCount + 5
If Range("A" & iloop2).Value = "Subtotal" And Range("A" & iloop2 + 1).Value = "Subtotal" Then
Range("A" & iloop2).Value = "Total"
End If
Next iloop2
'Soma os total
For iloop2 = 5 To iCount + 5
If Range("A" & iloop2).Value = "Total" Then
iCount2 = iloop2
MesmoTotal = True
While MesmoTotal
iCount2 = iCount2 + 1
If Range("A" & iCount2).Value = "Total" Or iCount2 >= 500 Then
QtdSubtotal = 0
MesmoTotal = False
Else
If Range("A" & iCount2).Value = "Subtotal" Then
QtdSubtotal = QtdSubtotal + 1
If QtdSubtotal = 1 Then
Range("D" & iloop2).Select
ActiveCell.Formula = "=SUM(D" & iCount2 & ")"
Range("E" & iloop2).Select
ActiveCell.Formula = "=SUM(E" & iCount2 & ")"
Range("F" & iloop2).Select
ActiveCell.Formula = "=SUM(F" & iCount2 & ")"
Range("G" & iloop2).Select
ActiveCell.Formula = "=SUM(G" & iCount2 & ")"
Range("H" & iloop2).Select
ActiveCell.Formula = "=SUM(H" & iCount2 & ")"
Range("I" & iloop2).Select
ActiveCell.Formula = "=SUM(I" & iCount2 & ")"
Range("J" & iloop2).Select
ActiveCell.Formula = "=SUM(J" & iCount2 & ")"
Range("K" & iloop2).Select
ActiveCell.Formula = "=SUM(K" & iCount2 & ")"
Range("L" & iloop2).Select
ActiveCell.Formula = "=SUM(L" & iCount2 & ")"
Range("M" & iloop2).Select
ActiveCell.Formula = "=SUM(M" & iCount2 & ")"
Range("N" & iloop2).Select
ActiveCell.Formula = "=SUM(N" & iCount2 & ")"
Range("O" & iloop2).Select
ActiveCell.Formula = "=SUM(O" & iCount2 & ")"
Else
Range("D" & iloop2).Select
MeiaFormula = Range("D" & iloop2).Formula
Range("E" & iloop2).Select
MeiaFormulaE = Range("E" & iloop2).Formula
Range("F" & iloop2).Select
MeiaFormulaF = Range("F" & iloop2).Formula
Range("G" & iloop2).Select
MeiaFormulaG = Range("G" & iloop2).Formula
Range("H" & iloop2).Select
MeiaFormulaH = Range("H" & iloop2).Formula
Range("I" & iloop2).Select
MeiaFormulaI = Range("I" & iloop2).Formula
Range("J" & iloop2).Select
MeiaFormulaJ = Range("J" & iloop2).Formula
Range("K" & iloop2).Select
MeiaFormulaK = Range("K" & iloop2).Formula
Range("L" & iloop2).Select
MeiaFormulaL = Range("L" & iloop2).Formula
Range("M" & iloop2).Select
MeiaFormulaM = Range("M" & iloop2).Formula
Range("N" & iloop2).Select
MeiaFormulaN = Range("N" & iloop2).Formula
Range("O" & iloop2).Select
MeiaFormulaO = Range("O" & iloop2).Formula
Range("D" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormula, Len(MeiaFormula) - 1) & ";D" & iCount2 & ")", ",", ";")
Range("E" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaE, Len(MeiaFormulaE) - 1) & ";E" & iCount2 & ")", ",", ";")
Range("F" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaF, Len(MeiaFormulaF) - 1) & ";F" & iCount2 & ")", ",", ";")
Range("G" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaG, Len(MeiaFormulaG) - 1) & ";G" & iCount2 & ")", ",", ";")
Range("H" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaH, Len(MeiaFormulaH) - 1) & ";H" & iCount2 & ")", ",", ";")
Range("I" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaI, Len(MeiaFormulaI) - 1) & ";I" & iCount2 & ")", ",", ";")
Range("J" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaJ, Len(MeiaFormulaJ) - 1) & ";J" & iCount2 & ")", ",", ";")
Range("K" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaK, Len(MeiaFormulaK) - 1) & ";K" & iCount2 & ")", ",", ";")
Range("L" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaL, Len(MeiaFormulaL) - 1) & ";L" & iCount2 & ")", ",", ";")
Range("M" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaM, Len(MeiaFormulaM) - 1) & ";M" & iCount2 & ")", ",", ";")
Range("N" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaN, Len(MeiaFormulaN) - 1) & ";N" & iCount2 & ")", ",", ";")
Range("O" & iloop2).Select
ActiveCell.FormulaLocal = Replace(Left(MeiaFormulaO, Len(MeiaFormulaO) - 1) & ";O" & iCount2 & ")", ",", ";")
End If
End If
End If
Wend
Range("A" & iloop2).Value = "Total"
End If
Next iloop2
End Subsegunda-feira, 6 de agosto de 2007 13:57
Todas as Respostas
-
Para maior segurança, você pode ter as duas macros, uma em cada idioma e disparar a macro correta após testar a configuração regional
Em alguns casos, você também pode optar por abrir a janela do Regional Settings e solicitar ao usuário que altere o idioma.
'Em General
Option Explicit'Pega as configurações
Private Declare Function GetLocaleInfo Lib "kernel32" Alias _
"GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, _
ByVal lpLCData As String, ByVal cchData As Long) As Long'Altera as configurações
Private Declare Function SetLocaleInfo Lib "kernel32" Alias _
"SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, _
ByVal lpLCData As String) As BooleanPrivate Declare Function GetUserDefaultLCID% Lib "kernel32" ()
Public Const CIngles = "English (United States)"
Public Const CPortugues = "Portuguese (Brazil)"'Constantes das Configurações Regionais
Const LOCALE_ICENTURY = &H24
Const LOCALE_ICOUNTRY = &H5
Const LOCALE_ICURRDIGITS = &H19
Const LOCALE_ICURRENCY = &H1B
Const LOCALE_IDATE = &H21
Const LOCALE_IDAYLZERO = &H26
Const LOCALE_IDEFAULTCODEPAGE = &HB
Const LOCALE_IDEFAULTCOUNTRY = &HA
Const LOCALE_IDEFAULTLANGUAGE = &H9
Const LOCALE_IDIGITS = &H11
Const LOCALE_IINTLCURRDIGITS = &H1A
Const LOCALE_ILANGUAGE = &H1
Const LOCALE_ILDATE = &H22
Const LOCALE_ILZERO = &H12
Const LOCALE_IMEASURE = &HD
Const LOCALE_IMONLZERO = &H27
Const LOCALE_INEGCURR = &H1C
Const LOCALE_INEGSEPBYSPACE = &H57
Const LOCALE_INEGSIGNPOSN = &H53
Const LOCALE_INEGSYMPRECEDES = &H56
Const LOCALE_IPOSSEPBYSPACE = &H55
Const LOCALE_IPOSSIGNPOSN = &H52
Const LOCALE_IPOSSYMPRECEDES = &H54
Const LOCALE_ITIME = &H23
Const LOCALE_ITLZERO = &H25
Const LOCALE_NOUSEROVERRIDE = &H80000000
Const LOCALE_S1159 = &H28
Const LOCALE_S2359 = &H29
Const LOCALE_SABBREVCTRYNAME = &H7
Const LOCALE_SABBREVDAYNAME1 = &H31
Const LOCALE_SABBREVDAYNAME2 = &H32
Const LOCALE_SABBREVDAYNAME3 = &H33
Const LOCALE_SABBREVDAYNAME4 = &H34
Const LOCALE_SABBREVDAYNAME5 = &H35
Const LOCALE_SABBREVDAYNAME6 = &H36
Const LOCALE_SABBREVDAYNAME7 = &H37
Const LOCALE_SABBREVLANGNAME = &H3
Const LOCALE_SCOUNTRY = &H6
Const LOCALE_SCURRENCY = &H14
Const LOCALE_SDATE = &H1D
Const LOCALE_SDAYNAME1 = &H2A
Const LOCALE_SDAYNAME2 = &H2B
Const LOCALE_SDAYNAME3 = &H2C
Const LOCALE_SDAYNAME4 = &H2D
Const LOCALE_SDAYNAME5 = &H2E
Const LOCALE_SDAYNAME6 = &H2F
Const LOCALE_SDAYNAME7 = &H30
Const LOCALE_SDECIMAL = &HE
Const LOCALE_SENGCOUNTRY = &H1002
Const LOCALE_SENGLANGUAGE = &H1001
Const LOCALE_SGROUPING = &H10
Const LOCALE_SINTLSYMBOL = &H15
Const LOCALE_SLANGUAGE = &H2
Const LOCALE_SLIST = &HC
Const LOCALE_SLONGDATE = &H20
Const LOCALE_SMONDECIMALSEP = &H16
Const LOCALE_SMONGROUPING = &H18
Const LOCALE_SMONTHNAME1 = &H38
Const LOCALE_SMONTHNAME10 = &H41
Const LOCALE_SMONTHNAME11 = &H42
Const LOCALE_SMONTHNAME12 = &H43
Const LOCALE_SMONTHNAME2 = &H39
Const LOCALE_SMONTHNAME3 = &H3A
Const LOCALE_SMONTHNAME4 = &H3B
Const LOCALE_SMONTHNAME5 = &H3C
Const LOCALE_SMONTHNAME6 = &H3D
Const LOCALE_SMONTHNAME7 = &H3E
Const LOCALE_SMONTHNAME8 = &H3F
Const LOCALE_SMONTHNAME9 = &H40
Const LOCALE_SABBREVMONTHNAME1 = &H44
Const LOCALE_SABBREVMONTHNAME2 = &H45
Const LOCALE_SABBREVMONTHNAME3 = &H47
Const LOCALE_SABBREVMONTHNAME4 = &H48
Const LOCALE_SABBREVMONTHNAME5 = &H49
Const LOCALE_SABBREVMONTHNAME6 = &H4A
Const LOCALE_SABBREVMONTHNAME7 = &H4B
Const LOCALE_SABBREVMONTHNAME8 = &H4C
Const LOCALE_SABBREVMONTHNAME9 = &H4D
Const LOCALE_SABBREVMONTHNAME10 = &H4E
Const LOCALE_SABBREVMONTHNAME11 = &H4F
Const LOCALE_SABBREVMONTHNAME12 = &H50
Const LOCALE_SMONTHOUSANDSEP = &H17
Const LOCALE_SNATIVECTRYNAME = &H8
Const LOCALE_SNATIVEDIGITS = &H13
Const LOCALE_SNATIVELANGNAME = &H4
Const LOCALE_SNEGATIVESIGN = &H51
Const LOCALE_SPOSITIVESIGN = &H50
Const LOCALE_SSHORTDATE = &H1F
Const LOCALE_STHOUSAND = &HF
Const LOCALE_STIME = &H1E
Const LOCALE_STIMEFORMAT = &H1003'CÒDIGO PARA O FORMULÁRIO:
Public Function Verifica_Regional(pLinguagem As String) ' PEGA simbolo decimal ATUALDim Symbol As String
Dim iRet1 As Long
Dim iRet2 As Long
Dim lpLCDataVar As String
Dim Pos As Integer
Dim Locale As Long
Dim msg As String
Verifica_Regional = False
Locale = GetUserDefaultLCID()
'Buscando definição do Regional Settings
iRet1 = GetLocaleInfo(Locale, LOCALE_SLANGUAGE, lpLCDataVar, 0)
Symbol = Space$(iRet1)
iRet2 = GetLocaleInfo(Locale, LOCALE_SLANGUAGE, Symbol, iRet1)
Pos = InStr(Symbol, Chr$(0))
Symbol = Left$(Symbol, Pos - 1)'------------------------------------------------------------------------------
If pLinguagem = CPortugues Then
If Symbol <> CPortugues Then
Verifica_Regional = True
msg = "A Linguagem padrão configurada no seu computador está como " & Symbol & "." & vbCrLf & vbCrLf
msg = msg & "Para o funcionamento da planilha ela deverá ser " & CPortugues & "." & vbCrLf & vbCrLf
msg = msg & "A seguir, será aberta a tela de Regional Settings para que seja feita a alteração."
MsgBox msg, vbExclamation
If MsgBox("Deseja alterar o idioma", vbYesNo, "Alterar o Regional Settings") = vbYes Then
Call Shell("rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,0", vbNormalFocus)
Else
Call 'NomeDaMacro'
End IfEnd If
Else
If Symbol <> CIngles Then
Verifica_Regional = True
Verifica_Regional = True
msg = "A Linguagem padrão configurada no seu computador está como " & Symbol & "." & vbCrLf & vbCrLf
msg = msg & "Para o funcionamento da planilha ela deverá ser " & CPortugues & "." & vbCrLf & vbCrLf
msg = msg & "A seguir, será aberta a tela de Regional Settings para que seja feita a alteração."
MsgBox msg, vbExclamation
If MsgBox("Deseja alterar o idioma", vbYesNo, "Alterar o Regional Settings") = vbYes Then
Call Shell("rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,0", vbNormalFocus)
Else
Call 'NomeDaMacro'
End IfEnd If
End If
End Functionsegunda-feira, 6 de agosto de 2007 19:41 -
Zerick_sp,
Testei com sucesso a função que recebi.
Porém, ela não resolve meu problema. Todas as máquinas aqui no escritório usam Portuguese Brasil nas regional settings o problema é que alguns dos excel são Excel 2003 Ingles e outros Excel 2003 Português.
Como faço para identificar a versão do office?
Grato,
Miguel Salles
segunda-feira, 13 de agosto de 2007 18:57 -
Olá,
o seu código original deveria funcionar, pois a fórmula em inglês passada pelo VBA funciona em qualquer idioma.
Creio que o problema esteja no PasteSpecial. A colagem foi feita por valor (Selection.PasteSpecial Paste:=xlPasteValues). Experimente colar as fórmulas, ou mesmo colar simples.
terça-feira, 14 de agosto de 2007 00:29Moderador -
Luiz,
A origem é um pivot table que aponta para um cubo do analysis services. Por esse motivo, não posso colar normal ou fórmulas.
Na minha planilha o "=sum(..." funciona, mas no excel portugues ("Arquivo" no lugar de "File") ele não entende.
Alguma dica?
Grato,
Miguel Salles
terça-feira, 14 de agosto de 2007 14:08