Notifications
Clear all

Importar dados da web e nomear planilha a parti de lista

2 Posts
1 Usuários
0 Reactions
826 Visualizações
(@adriana88)
Posts: 6
Active Member
Topic starter
 

Boa tarde a todos,

Estou importando páginas da web através de links que estão na coluna A, sendo que cada página importada gera uma nova planilha. Queria que cada planilha gerada fosse nomeada conforme o nome que está na coluna B.

Agradeço aqueles que melhorasse esse código que não funciona. As planilhas são importadas, mas também são geradas planilhas em branco com os nomes que fosse nomeadas as das páginas importadas.

Sub URLTest()
    
    Dim rngURL As Range
    Dim nameURL As Range
             
            
    
    'Loop through each used cell in column A on sheet URLs
    For Each rngURL In Worksheets("URLs").Range("A1", Worksheets("URLs").Range("A" & Rows.Count).End(xlUp))
   
    
               
        Worksheets.Add
        With ActiveSheet.QueryTables.Add(Connection:="URL;" & rngURL.Value, Destination:=ActiveSheet.Range("A1"))
     
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
        End With
              
   
         
        Next
         For Each nameURL In Worksheets("URLs").Range("B1", Worksheets("URLs").Range("B" & Rows.Count).End(xlUp))
         Worksheets.Add.name = nameURL.Value
        
        Next
        
        
    End Sub
 
Postado : 27/01/2017 10:06 am
(@adriana88)
Posts: 6
Active Member
Topic starter
 

Solução

Sub URLTest()
    Dim rngURL As Range
        
    'Loop through each used cell in column A on sheet URLs
    For Each rngURL In Worksheets("URLs").Range("A1", Worksheets("URLs").Range("A" & Rows.Count).End(xlUp))
       
        Worksheets.Add
        ActiveSheet.Name = rngURL.Offset(0, 1).Value
        With ActiveSheet.QueryTables.Add(Connection:="URL;" & rngURL.Value, Destination:=ActiveSheet.Range("A1"))
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlOverwriteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
        End With
        
 Next
 
End Sub
 
Postado : 31/01/2017 6:53 pm