2013-03-17 43 views
0

我試圖添加引用到我的項目,所以我可以得到這個錯誤解決,但我沒有成功。用戶類型未定義工作表VBA

任何人都可以告訴我應該添加哪些庫嗎?

Dim objFSO As Object 
Dim objFolder As Object 
Dim objFile As Object 
Dim ws As Worksheet 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set ws = Worksheets.Add 

'Get the folder object associated with the directory 
Set objFolder = objFSO.GetFolder("C:\") 
ws.Cells(1, 1).Value = "The files found in " & objFolder.Name & "are:" 

'Loop through the Files collection 
For Each objFile In objFolder.Files 
    ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name 
    MyFile = objFile.Name 
     NewName = getNewFileName() 
+1

您正在使用後期綁定,因此您不需要添加引用(請參閱http://support.microsoft.com/kb/245115)。錯誤在哪裏? – CuberChase 2013-03-17 23:05:41

回答

2

如果您的Word IDE內工作然後去工具 - >引用和瀏覽的Microsoft Excel [版本號]對象庫

enter image description here

1

您已經標記的問題字VBA,但您使用的是Worksheets參考,這是Excel的一部分。

如果你真的在Word中使用Worksheets引用,你會得到User-defined type not defined-錯誤。

如果沒有,還有其他缺失,您需要告訴我們更多。什麼線做了錯誤的亮點等

相關問題