Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6538872
  • 博文数量: 915
  • 博客积分: 17977
  • 博客等级: 上将
  • 技术积分: 8846
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-26 09:59
个人简介

一个好老好老的老程序员了。

文章分类

全部博文(915)

文章存档

2022年(9)

2021年(13)

2020年(10)

2019年(40)

2018年(88)

2017年(130)

2015年(5)

2014年(12)

2013年(41)

2012年(36)

2011年(272)

2010年(1)

2009年(53)

2008年(65)

2007年(47)

2006年(81)

2005年(12)

分类: WINDOWS

2006-11-07 10:53:16

WD97: Word VBA 中使用 Open 语句

注意:这篇文章是由无人工介入的自动的机器翻译系统翻译完成。这些文章是微软为不懂英语的用户提供的, 以使他们能够理解这些文章的内容。微软不保证机器翻译的正确度,也不对由于内容的误译或者客户对它的使用所引起的任何直接的, 或间接的可能的问题负责。
文章编号 : 181788
最后修改 : 2005年6月17日
修订 : 2.0

概要

Open 语句是是 Microsoft Visual Basic for Applications 语言一部分。 此命令使您得以打开数据文件用于读取、 修改, 或添加到文件。

没有备注: Open 语句不打开到工作区文件, 由宏只打开用于处理文件。

备注: Open 语句不用于打开程序拥有文件类型。 例如, 执行不使用打开来打开 Word 文档、 MicrosoftExcel 电子表格或 MicrosoftAccess 数据库。 这样做会导致丢失文件完整性和文件损坏。
回到顶端

更多信息

Microsoft 提供编程示例仅, 用于说明目的不附带任何明示或暗示, 包括但不限于, 暗示保证了适销性和/或用于特定目的适用性,。 本文假设您是熟悉正在演示编程语言和工具用于创建和调试过程。 Microsoft 支持专家可以帮助解释了某个特定过程, 功能但是它们不会修改这些示例以提供添加功能或构建过程以满足您特定需要。 如果您具有有限编程经验, 要联系 Microsoft 认证合作伙伴或 Microsoft 收费咨询行 (800) 936 - 5200 上。 有关 Microsoft 认证伙伴, 请访问下列 Microsoft Web 站点:
()
有关如何联系 Microsoft, 有关可支持选项和请访问以下 Microsoft 网站:
()
用于打开语句正确语法是:
   Open pathname For mode [access] [lock] As [#]filenumber [Len=reclength]
				
Open 语句语法具有下列组成部分。
Part            Description
---------------------------

pathname        Required. String expression that specifies a file name may
                include directory or folder, and drive.

    mode        Required. Keyword specifying the file mode: Append, Binary,
                Input, Output, or Random. If unspecified, the file is
                opened for Random access.

  access        Optional. Keyword specifying the operations permitted on
                the open file: Read, Write, or Read Write.

    lock        Optional. Keyword specifying the operations permitted on
                the open file by other processes: Shared, Lock Read, Lock
                Write, and Lock Read Write.

filenumber      Required. A valid file number in the range 1 to 511,
                inclusive. Use the FreeFile function to obtain the next
                available file number.

reclength       Optional. Number less than or equal to 32,767 (bytes). For
                files opened for random access, this value is the record
                length. For sequential files, this value is the number of
                characters buffered.
				
回到顶端

语句示例

   Sub OpenExample()

      Dim sFirst, sLast, sAddress, sCity, sState, sZip As String

      ' CREATE DATA FILE
      ' Open file for input.
      Open "Datafile.txt" For Output As #1

      ' Write data to file.
      Write #1, "John", "Doe", "An Address", "A City", "A State", "A Zip"

      ' Close File.
      Close #1

      ' RETRIEVE DATA FROM FILE
      ' Open file for input.
      Open "Datafile.txt" For Input As #1

      ' Loop until the end of file is reached.
      Do While Not EOF(1)

         ' Read data into variables.
         Input #1, sFirst,sLast,sAddress,sCity,sState,sZip

         ' Print data to Debug window.
         Debug.Print sFirst,sLast,sAddress,sCity,sState,sZip

      Loop

      ' Close file.
      Close #1

   End Sub
				
该宏创建或打开称为 Datafile.txt 文件并将逗号和引号分隔数据放入文件。 可再后面使用输入 # Statement 检索数据。
回到顶端

参考

有关将数据写入文件, Office 助手中 VisualBasic 编辑器时, 键入 向文件写入数据 , 单击搜索, 依次查看 " 书写数据向文件 "。

有关其他信息, 请参见以下 Microsoft 知识库文章:
() 97: 如何从知识库文章运行示例代码
有关获取与 VisualBasic 帮助 VisualBasicforApplications, 请参见下列文章 Microsoft 知识库文章:
() 用于 Visual Basic for Applications VBA: 编程资源
回到顶端

这篇文章中的信息适用于:
Microsoft Word 97 Standard Edition
回到顶端
关键字: 
kbdtacode kbhowto kbmacroexample KB181788 KbMtzh kbmt
回到顶端
Microsoft和/或其各供应商对于为任何目的而在本服务器上发布的文件及有关图形所含信息的适用性,不作任何声明。 所有该等文件及有关图形均"依样"提供,而不带任何性质的保证。Microsoft和/或其各供应商特此声明,对所有与该等信息有关的保证和条件不负任何责任,该等保证和条件包括关于适销性、符合特定用途、所有权和非侵权的所有默示保证和条件。在任何情况下,在由于使用或运行本服务器上的信息所引起的或与该等使用或运行有关的诉讼中,Microsoft和/或其各供应商就因丧失使用、数据或利润所导致的任何特别的、
阅读(5109) | 评论(0) | 转发(0) |
0

上一篇:安装vmware-tools时出错

下一篇:VBA语法基础

给主人留下些什么吧!~~