没有定义的bloc的object.getfolder错误变量

时间:2015-08-12 08:49:57

标签: excel vba

我正在编写代码以将文件夹的所有文件导入一个Excel工作表。这是我的代码:

Sub ImportLiabs()
Dim destination As String
Dim Colonne1Tableau As Integer
Dim Ligne1Tableau As Integer
Dim nb_onglets_param As Integer
Dim OngletMacro As String
Dim i As Integer: i = 1
Dim folder As String

  'Paramétrage
destination = ThisWorkbook.Name
Dim NomFichier() As String

Dim MyObj As Object, MySource As Object, file As Variant
folder = Range("Folder").Value
Set MyObject = CreateObject("Scripting.FileSystemObject")
Set MySource = MyObj.GetFolder(folder)
For Each file In MySource.Files

        If Left(file.Name, 9) = "liab_data" Then

        i = i + 1
        ReDim Preserve NomFichier(i)
        NomFichier(i) = file.Name

        Workbooks.Open file
        Sheets.Copy After:=Workbooks(destination).Sheets(i)
        Windows(NomFichier(i)).Close


        i = i + 1


    End If
    Next file


End Sub

问题在于,当它显示时,变量或对象没有在此行中定义块:

Set MySource = MyObj.GetFolder(folder)

无法确定问题所在,谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

您定义变量MyObj,然后使用Set MyObject = CreateObject("Scripting.FileSystemObject") Set MySource = MyObject.GetFolder(folder) 设置文件夹。

试试这个:

<ul class="woof_list woof_list_radio">
<li >
    <input type="radio" id="woof_72_55cb07a61800a" class="woof_radio_term" data-slug="elektronik" name="product_cat" value="72">
    <label for="woof_72_55cb07a61800a">Elektronik <span>(812)</span></label>
</li>
<li >
    <input type="radio" id="woof_113_55cb07a741fec" class="woof_radio_term" data-slug="pompa-air" name="product_cat" value="113" checked="checked">
    <label for="woof_113_55cb07a741fec" checked="checked" style="font-weight: bold;">Pompa Air <span>(29)</span></label>
</li>
<li >
    <input type="radio" id="woof_184_55cb07a7513ac" class="woof_radio_term" data-slug="brand" name="product_cat" value="184">
    <label for="woof_184_55cb07a7513ac">Brand <span>(814)</span></label>
</li>
</ul>