示例1

' 获取当前文件夹
CurDir(“D:\”)
' 重命名
Name "C:\System.1st " As "D:\test.txt"

检查文件或文件夹是否存在
Dir("C:\", vbNormal)
If Dir("C:\stamp.bat") = "" Then Debug.Print "文件未找到。"

' 获得文件修改的日期和时间
FileDateTime("C:\config.sys")
DateValue(FileDateTime("C:\config.sys"))
TimeValue(FileDateTime("C:\config.sys"))

' 获得文件大小
FileLen("C:\WINDOWS\" & iniFile)

' GetAttr函数来获得文件或文件夹的属性
GetAttr("C:\MSDOS.SYS")
SetAttr "C:\stamps.txt", vbReadOnly + vbHidden

' 创建一个新文件夹
MkDir "C:\Mail"

ChDir "C:\Mail"

' 删除文件夹
RmDir "C:\Mail"

' 拷贝文件
FileCopy source, dest

' 删除文件
Kill 文件路径名

示例2

Sub ReadMe()
	Dim rLine As String
	Dim i As Integer ' line number
	i = 1
	
	Open "C:\Autoexec.bat" For Input As #1
	Do While Not EOF(1)
		Line Input #1, rLine
		MsgBox "Line " & i & " in Autoexec.bat reads: " _
		& Chr(13) & Chr(13) & rLine
		i = i + 1
	Loop
	
	MsgBox i & " lines were read."
	Close #1
End Sub

示例3

Sub Colons()
	Dim counter As Integer
	Dim char As String
	counter = 0
	
	Open "C:\Autoexec.bat" For Input As #1
	Do While Not EOF(1)
		char = Input(1, #1)
		If char = ":" Then
		counter = counter + 1
		End If
	Loop
	
	If counter <> 0 Then
		MsgBox "Characters found: " & counter
	Else
		MsgBox "The specified character has not been found."
	End If
	
	Close #1
End Sub

示例4

Sub WriteToTextBox()
	Dim mysheet As Worksheet
	Set mysheet = ActiveWorkbook.Worksheets(1)
	
	On Error GoTo CloseFile
	
	Open "C:\WINNT\System.ini" For Input As #1
	mysheet.Shapes(1).Select
	Selection.Characters.Text = Input(LOF(1), #1)
	
	CloseFile:
	Close #1
End Sub