Ir ao conteúdo
  • Cadastre-se

Basole

Membro Pleno
  • Posts

    2.019
  • Cadastrado em

posts postados por Basole

  1. @isabela queiroz testei o codigo que modificou e está funcionando perfeitaemnte.

     

    De qualquer forma alterei o codigo para copiar celula por celula. (* este processo pode demorar dependendo dos seus dados).

    Acrescentei tambem o comando para ocultar a aba de exemplo. 

     

    *Para o comando ocultar aba, funcione sem erro, precisa acrescentar antes, o comando para ativar uma outra aba que esteja visivel.

     

    Salvar_Sheet_Novo_Arquivo.zip

    • Curtir 1
    • Amei 1
  2. Com vba é possível, mas é necessario analisar melhor a formatação do seu arquivo

     

    Segue um exemplo generico: 

     

     

    Sub LerImportarTXT()
        Dim fso         As Object
        Dim sourceFile  As Object
        Dim myFilePath  As String
        Dim myFileText  As String
        Dim LR!
        Dim line        As String

        Set fso = CreateObject("Scripting.FileSystemObject")
        myFilePath = "C:\Temp\txt\Teste.txt" 'ALTERE O LOCAL E NOME DO ARQUIVO

        LR = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1).Row

        Set sourceFile = fso.OpenTextFile(myFilePath, 1)
        If Not sourceFile.AtEndOfStream Then
            line = sourceFile.ReadLine

            With ActiveSheet
                .Cells(LR, 1) = VBA.Trim(VBA.Mid(line, 3, 13)) ' NOME: caractere 03 ate 15 (tamanho 13)
                .Cells(LR, 2) = VBA.Trim(VBA.Mid(line, 16, 15)) 'CIDADE: caractere 16 ate 30 (tamanho 15)
                .Cells(LR, 3) = VBA.Trim(VBA.Mid(line, 31, 5))  ' NUMERO DO PEDIDO: caractere 31 ate 35 (tamanho 5)
                .Cells(LR, 4) = VBA.Trim(VBA.Mid(line, 36, 1))  'ORDEM: caractere 36 (tamanho 1)
            End With
        End If
        sourceFile.Close
    End Sub

     

     

     

    • Curtir 1
  3. @Andreza Santos

     

    Fiz alterações na sub Inserir_Clientes

     

    Sub Inserir_clientes()
        Dim tabela_clientes As ListObject
        Dim n           As Integer
        Dim id          As Integer
        Dim ws          As Worksheet
    
        Set ws = Sheets("Clientes")
        Set tabela_clientes = ws.ListObjects("Clientes")
    
        id = Range("ID").Value
        With tabela_clientes
            .ListRows.Add
    
            n = .DataBodyRange.Columns(1).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
            .DataBodyRange(RowIndex:=n, columnindex:=1).Value = id
            .DataBodyRange(RowIndex:=n, columnindex:=2).Value = Sistema.txt_nome.Value
            .DataBodyRange(RowIndex:=n, columnindex:=3).Value = Sistema.cbb_sexo.Value
            .DataBodyRange(RowIndex:=n, columnindex:=4).Value = Sistema.txt_telefone.Value
            .DataBodyRange(RowIndex:=n, columnindex:=5).Value = Sistema.txt_cep.Value
            .DataBodyRange(RowIndex:=n, columnindex:=6).Value = Sistema.txt_endereco.Value
            .DataBodyRange(RowIndex:=n, columnindex:=7).Value = Sistema.txt_numero.Value
            .DataBodyRange(RowIndex:=n, columnindex:=8).Value = Sistema.txt_bairro.Value
            .DataBodyRange(RowIndex:=n, columnindex:=9).Value = Sistema.txt_local.Value
    
            Range("ID").Value = id + 1
    
            With Sistema
                .txt_nome.Text = ""
                .cbb_sexo.Text = ""
                .txt_telefone.Text = ""
                .txt_cep.Text = ""
                .txt_endereco.Text = ""
                .txt_numero.Text = ""
                .txt_bairro.Text = ""
                .txt_local.Text = ""
            End With
    
    
            Call Atualizar_listclientes
    
            MsgBox "Cadastrado com sucesso!", vbInformation, "Informação"
    
        End With
    End Sub

     

    *Caso o erro persista, tente deletar toda a tabela "Clientes" e inserir novamente.

    • Amei 1
  4. @Andreza Santos aqui pra mim só apareceu erro na hora de atualizar, na 

    Sub Atualizar_listclientes

     

    Fiz umas pequenas alterações, ai funcionou sem problemas:

    Ficou assim:  

     

    Sub Atualizar_listclientes()
        Dim tabela      As ListObject
    
        Set tabela = Worksheets("Clientes").ListObjects("Clientes")
        With Sistema.cbb_clientes
            .RowSource = ""
            .Clear
            .ColumnCount = 2
            .List = tabela.DataBodyRange.Value2
        End With
    End Sub

     

  5. @diego_janjao para criar uma pasta neste formato [ 01.Janeiro ], de acordo com a coluna "E", substitue

     

    Esta linha:

     

     save = ThisWorkbook.Path & "\" & Format(Cells(Target.Row, 4).Value, "000000") & " - " & Cells(Target.Row, 8).Value & " - " & Cells(Target.Row, 11).Value

     

     

    por esta:

     

    save = ThisWorkbook.Path & "\" & VBA.Month(Cells(Target.Row, 5).Value) & "." & VBA.StrConv(VBA.MonthName(VBA.Month(Cells(Target.Row, 5).Value)), 3) 

     

    • Obrigado 1
  6. @rosanezane

    No recurso da mala direta do Word, não encontrei nenhuma opção de agrupar novos documentos em um unico. 

    A opção seria a de copiar e colar os docs criados individualmente em um unico documento, (como no exemplo do @Midori ), mas devido a dimensão dos dados, aqui pra mim, ao fazer isso as paginas não mantem a formatação original da Folha de Ponto, "pulando" para a pagina de baixo:

     

    image.png.bf4fd96c74b68dbb4b118cb427353fab.png

     

    Outra opção é salvar todos os documentos individuais em pdf, em seguida, atraves de utilitário agrupa-los de acordo com cada empresa.

     

    Estou ajustando a macro e mais tarde posto aqui. 

     

     

    • Curtir 1
  7. @vigue se o problema for com o caminho longo (com + de 255 caracteres), tente usar a função que encurta o path:

     

     

    Sub SalvaCopia()
    
    Dim ToPath As String
    ToPath = "\\endereco.sharepoint.com\sites\teste\Documentos Compartilhados\pasta backup"
    Nome_backup = "planilha backup.xlsm"
    
    ActiveWorkbook.SaveCopyAs Filename:= _
    GetShortPath(ToPath & "\Backups da conferencia diaria\" & Nome_backup)
    
    End Sub
    
    Public Function GetShortPath(path As String) As String
    ' função que encurta o caminho(path), abaixo limite 256 caract.
      Dim fso As Object
      If fso Is Nothing Then
      Set fso = VBA.CreateObject("Scripting.FileSystemObject")
      End If
     
      If fso.FileExists(path) Then
          GetShortPath = fso.GetFile(path).ShortPath
          Exit Function
      End If
     
      If fso.FolderExists(path) Then
          GetShortPath = fso.GetFolder(path).ShortPath
          Exit Function
      End If
      
    End Function

     

  8. 2 horas atrás, marcospires1 disse:

    Sem querer abusar, um dos campos é data e causa erro na macro, sabe como posso corrigir?

    Visto que a data vai ser inserida por outras pessoas utilizando este arquivo.

     

    @marcospires1 bom considerando que a data esteja na celula A1 segue exemplo: 

     

    With ActiveSheet
    
    LOCALNOME = ThisWorkbook.Path & "\Pedido" & "_" & VBA.Format(.[A1], "dd-mm-yyyy") & .[K2] & .[G5] & ".pdf"
    
    End With

     

     

    Pode-se tambem alterar a formatação da data colocando ao contrario, ou seja ano-mes-dia 

     

    LOCALNOME = ThisWorkbook.Path & "\Pedido" & "_" & VBA.Format(.[A1], "yyyy-mm-dd") & .[K2] & .[G5] & ".pdf"

     

     

    • Curtir 1
    • Obrigado 1

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...