• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

TXT uzantılı dosya açma makrosundaki hata...

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...

vardar07

Destek Ekibi
Destek Ekibi
Katılım
19 Mart 2008
Mesajlar
2,154
Excel Vers. ve Dili
Office 2007 Enterprise
Türkçe
[çözüldü] TXT uzantılı dosya açma makrosundaki hata...

Merhaba arkadaşlar aşağıdaki kodda kırmızı ile belirtilen yerde combobox ile dosya seçimi yapıp label üzerinden açmaya çalışıyorum ancak kırmızılı yerde hata veriyor. Mavi ile belirtilen gibi direk yazınca dosyayı açıyor. nerede eksik yada fazla var.

Kod:
Private Sub CommandButton1_Click() 
Label1 = ComboBox1.Text
[COLOR="red"]''''''''''''''''''''''''''''''''' hatalı kod '''''''''''''''''''''''''' 
  Const szFileName As String =  Label1.Caption & ".txt"[/COLOR]
 [COLOR="Blue"]  '''''''''''''''''''''''''''''''' çalışan ''''''''''''''''''''''''''''''''
Const szFileName As String =   "Duyuru.txt"[/COLOR]

With Me
        .ListBox1.Clear
        .Label1.Caption = Empty
    End With
    Dim szThisPath As String
        szThisPath = ThisWorkbook.Path
    Dim szPathSep As String
        szPathSep = Application.PathSeparator
    Dim szValidPath As String
        szValidPath = szThisPath & szPathSep & szFileName
    Me.Label1.Caption = "Dosya Yolu:  " & szValidPath
    On Error GoTo ErrHandler
    Dim lFile As Long
    Dim szLine As String
  lFile = FreeFile()
   Open szValidPath For Input As lFile
        While Not EOF(lFile)
            Line Input #lFile, szLine
            Me.ListBox1.AddItem szLine
        Wend
    Close lFile
  Exit Sub
ErrHandler:
    Me.Label1.Caption = Empty
    MsgBox Err.Description
End Sub

Private Sub UserForm_Initialize()
    With Me
        .ListBox1.Clear
        .ComboBox1.Text = Empty
        .Label1.Caption = Empty
    End With
Label1 = ComboBox1.Text
End Sub
 
Son düzenleme:
Arkadaşlar sorun aşağıdaki şekilde çözülmüştür.

Kod:
Option Explicit

Private Sub ComboBox1_Change()
CommandButton1_Click
Label2.Visible = False
End Sub


Private Sub UserForm_Initialize()
With Sheets("veri")
ComboBox1.RowSource = "veri!a1:a" & .Range("a65536").End(xlUp).Row
End With
    
    With Me
        .ListBox1.Clear
        .ComboBox1.Text = Empty
        .Label1.Caption = Empty
    End With
End Sub

Private Sub CommandButton1_Click()
  Label2.Caption = ComboBox1.Text
   Dim szFileName As String
   szFileName = Label2 & ".txt"
   With Me
        .ListBox1.Clear
        .Label1.Caption = Empty
    End With
    Dim szThisPath As String
        szThisPath = ThisWorkbook.Path
    Dim szPathSep As String
        szPathSep = Application.PathSeparator
    Dim szValidPath As String
        szValidPath = szThisPath & szPathSep & szFileName
    Me.Label1.Caption = "Dosya Yolu:  " & szValidPath
    On Error GoTo ErrHandler
    Dim lFile As Long
    Dim szLine As String
  lFile = FreeFile()
   Open szValidPath For Input As lFile
        While Not EOF(lFile)
            Line Input #lFile, szLine
            Me.ListBox1.AddItem szLine
        Wend
    Close lFile
  Exit Sub
ErrHandler:
    Me.Label1.Caption = Empty
    MsgBox Err.Description

End Sub

Kullanmak isteyenler aşağıdaki linkten 4 nolu mesajdaki dosyayı inceleyebilir.

http://www.excel.web.tr/f48/userform-uzerinde-txt-uzantyly-dosya-acma-t135846.html
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Geri
Üst