Vídeo recomendado
https://youtu.be/diWPPPhW-9E

VBA - Aplicar macro para planilhas em uma pasta especifica

Dúvidas gerais sobre Excel
marciofirmino_
Acabou de chegar
Acabou de chegar
Mensagens: 1
Registrado em: Qua Jun 16, 2021 10:32 pm

VBA - Aplicar macro para planilhas em uma pasta especifica

Mensagem por marciofirmino_ »

Pessoal, boa noite e muito prazer!

Estou tentando criar um script em uma planilha "mestra" na qual toda vez que eu executar a macro desta planilha, ela irá repetir essa macro para todas as planilhas de uma pasta em específico. Consegui desenvolver o seguinte código abaixo. Entretanto, o código do jeito que está, está dando o erro "Metodo Select da Classe Range Falhou - 1004". Pesquisando algumas resoluções, acredito que seja por estar chamando um objeto wb dentro do sub dowork. Como sou iniciante no VBA, não sei como ajustar o código, ou refazer de alguma maneira melhor. Alguém poderia me ajudar?

Desde já, muito obrigado!

obs: Sou iniciante no fórum, se eu postei algo de errado por favor me alertem que corrigirei o mais rapido possivel :D.

Sub ProcessFiles()

Dim Filename, Pathname As String

Dim wb As Workbook



Pathname = ActiveWorkbook.Path & "\Files\"

Filename = Dir(Pathname & "*.xls")

Do While Filename <> ""

Set wb = Workbooks.Open(Pathname & Filename)

DoWork wb

wb.Close SaveChanges:=True

Filename = Dir()

Loop

End Sub



Sub DoWork(wb As Workbook)

With wb

'Do your work here

Dim Ultima_coluna As Long

Dim linha As Variant

Dim ultima_linha As Long

Dim coluna As Variant





.Worksheets("Sheet1").Range("F2").Select

Ultima_coluna = Cells(2, Columns.Count).End(xlToLeft).Column

ultima_linha = Range("A" & Rows.Count).End(xlUp).Row

linha = 0

coluna = 0



Do While linha <= ultima_linha

Do While coluna <= Ultima_coluna



If ActiveCell = "Nunca" Then 'faz a análise lógica

ActiveCell.Value = 0

ElseIf ActiveCell = "Raramente" Then

ActiveCell.Value = 1

ElseIf ActiveCell = "As vezes" Then

ActiveCell.Value = 2

ElseIf ActiveCell = "Frequente" Then

ActiveCell.Value = 3

ElseIf ActiveCell = "Sempre" Then

ActiveCell.Value = 5

End If

coluna = coluna + 1



Range("F2").Select

ActiveCell.Offset(linha, coluna).Select

Loop

Range("F2").Select

coluna = 0



linha = linha + 1



ActiveCell.Offset(linha, coluna).Select

Loop



ActiveCell.Value = "AMBIDESTRIA: " & (5) * 0.2

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = "TOMADA DE DECISAO: " & (5) * 0.15

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = "GESTAO HUMANIZADA: " & (5) * 0.15

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = "EMBAIXADOR DA CULTURA: " & (5) * 0.15

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = "CLIENTE NO CENTRO: " & (5) * 0.15

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = "VAI ALEM DO ESPERADO: " & (5) * 0.2

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = "Valor Final: " & (5)



End With

End Sub


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Responder