上次点差了,把分数弄没了,实在是不好意思...虽然大虾不在意那点分但那也是劳动成果..呵呵~!谢谢..在D:\ABC 文件夹下面有多种格式的文档资料 
现在在WORKSHEET中做了个BUTTON点击此BOTTON后 
自动把D:\ABC 下面的所有 XLS 类型的文档资料的名字取到并且输出到当前WORKSHEET中的指定位置,以下 
为实现代码.为什么在WORKSHEET中的指定位置看不到所找到的文档资料的名字?帮忙看看谢谢 
代码如下: Private Sub CommandButton_Click() 
Dim NextRow As Long 
Dim myPath, myDate As String 
Dim strTemp$ 
Dim filename As String 
Sheets("xxx").Activate 
    If TextBox1.Text = "" Then 
    MsgBox ("日期(YYYYMMDD)を入力してください") 
    Else 
filename = "*.xls" 
strTemp = Trim$(TextBox1.Text) 
myDate = Mid(strTemp, 1, 6) myPath = "D:\ABC " & myDate & "\" & strTemp 
filename = Dir(myPath & filename, vbDirectory) 
  While filename <> "" 
        filename = Dir()   Wend 
        Mysave (filename) 
  End If 
End Sub 
Private Sub Mysave(strYw As String) 
Dim l As Long 
Dim n As Long 
n = Worksheets("xxx").Range("A65535").End(xlUp).Row 
l = [A65535].End(xlUp).Row + 1 
If n < 4 Then 
//以下大家只要看Range("C" & l)就可以了.. 
Range("A" & l) = 1 
Range("B" & l) = IIf(OptionButton7, OptionButton7.Caption, OptionButton8.Caption) 
Range("C" & l) = strYw 
Range("D" & l) = IIf(OptionButton3, OptionButton3.Caption, OptionButton4.Caption) 
Range("E" & l) = TextBox1 
Range("F" & l) = IIf(OptionButton6, OptionButton6.Caption, OptionButton9.Caption) + Mid(TextBox1.Text, 1, 6) + "/" + TextBox1.Text 
Range("G" & l) = TextBox2 
Else 
Range("A" & l) = Range("A" & l - 1) + 1 
Range("B" & l) = IIf(OptionButton7, OptionButton7.Caption, OptionButton8.Caption) 
Range("C" & l) = strYw 
Range("D" & l) = IIf(OptionButton3, OptionButton3.Caption, OptionButton4.Caption) 
Range("E" & l) = TextBox1 
Range("F" & l) = IIf(OptionButton6, OptionButton6.Caption, OptionButton9.Caption) + Mid(TextBox1.Text, 1, 6) + "/" + TextBox1.Text 
Range("G" & l) = TextBox2 
End If 
End Sub

解决方案 »

  1.   


    '你的代码段:
    filename = Dir(myPath & filename, vbDirectory) 
      While filename <> "" 
            filename = Dir()   Wend 
            Mysave (filename) 
      End If 
    End Sub 
    '改为下面这样:应该每读一条就写一次.而不应该读完了再写.  filename = Dir(myPath & filename, vbDirectory) 
      While filename <> "" 
            Mysave (filename)
            filename = Dir() 
      Wend 
             
    End If 
    End Sub 
      

  2.   

    我试了一下..
     那样改的话什么都没了,以前就C列对应位置输出不了值
    别 现在这样的话连ABDEF列的都输出不上去了.呵呵~!
      

  3.   

    myPath = "D:\ABC " & myDate & "\" & strTemp 
    改为
    myPath = "D:\ABC " & myDate & "\" & strTemp & "\"你最好确认一下
    myPath & filename 的值是不是一个完整的路径名.