在excel中包含文件以在VBA中使用

时间:2014-05-29 18:35:59

标签: excel vba excel-vba

我正在使用用户浏览特定文件的代码,然后将该文件写入文本文件。有没有办法在excel文件中包含此文件,因此不必定位它。该文件是一个4mb km的文件。

Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
intChoice = Application.FileDialog(msoFileDialogOpen).Show
If intChoice <> 0 Then
    newFile = Application.FileDialog( _
        msoFileDialogOpen).SelectedItems(1)
End If


Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(newFile)

Print #1, f.ReadAll

Set f = Nothing
Set fs = Nothing

1 个答案:

答案 0 :(得分:0)

嗯,微软说Total number of characters that a cell can contain: 32,767 characters。您可以做的是逐行读取文件 - 使用循环中的ReadLine而不是ReadAll - 进入隐藏工作表的单元格,尽管格式化可能会丢失。 http://support.microsoft.com/kb/186118/en