Boa tarde pessoal do Clube! Preciso de uma pequena ajuda num comando aqui.
tenho o código abaixo que faz referência/busca a uma sheet dentro do próprio arquivo.
estou tentando fazer a busca em um outro arquivo que fica no servidor, porém não esta dando certo.
alguém pode me ajudar?
código atual (funcionando)
Option Explicit
Private TextoDigitado As String
Private Sub ListBox1_Click()
ActiveCell.Value = ListBox1.Value
Unload Me
End Sub
Private Sub UserForm_Initialize()
Call PreencheLista
End Sub
Private Sub PreencheLista()
Dim ws As Worksheet
Dim i As Integer
Dim TextoCelula As String
Set ws = ThisWorkbook.Worksheets(9)
i = 1
ListBox1.Clear
With ws
While .Cells(i, 8).Value <> Empty
TextoCelula = .Cells(i, 8).Value
If UCase(Left(TextoCelula, Len(TextoDigitado))) = UCase(TextoDigitado) Then
ListBox1.AddItem .Cells(i, 8)
End If
i = i + 1
Wend
End With
End Sub
código que estou tentando ajustar:
Option Explicit
Private TextoDigitado As String
Private Sub ListBox1_Click()
ActiveCell.Value = ListBox1.Value
Unload Me
End Sub
Private Sub TextBox1_Change()
TextoDigitado = TextBox1.Text
Call PreencheLista
End Sub
Private Sub UserForm_Initialize()
Call PreencheLista
End Sub
Private Sub PreencheLista()
Dim wb As Workbook: Set wb = ActiveWorkbook
Dim ws As Worksheet
Dim strTemplate As String: strTemplate = "Z:\BANCO_DADOS\DADOS.xls"
Set ws = wb.Sheets.Add(Type:=strTemplate)(9)
i = 1
ListBox1.Clear
With ws
While .Cells(i, 2).Value <> Empty
TextoCelula = .Cells(i, 2).Value
If UCase(Left(TextoCelula, Len(TextoDigitado))) = UCase(TextoDigitado) Then
ListBox1.AddItem .Cells(i, 2)
End If
i = i + 1
Wend
End With
End Sub