excel - VBA Excel: how to use a variable for the file number used for open, print and close
问题描述
I would like to use a variable for the file number, instead of hard-coding it.
I have tried with conversions like CDbl to have a double, as it seems that #1 means convert 1 into double.. But this did not work. It also does not work without conversion, so until now, using #1 (or any number) is the only way to interact with a file that worked fine.
Open f_output For Append As #2
Print #2, "hello"
Close #2
I would like it to look like
dim fileNumber as double
fileNumber = 2
Open f_output For Append As fileNumber
Print fileNumber, "hello"
Close fileNumber
解决方案
Here is the answer I was looking for.
dim fileNum
fileNum = 3
Open f_output For Append As #fileNum
Print #fileNum, s
Close #fileNum
Additionally, the built-in function FreeFile can be used to get a free file number.
fileNum = FreeFile
推荐阅读
- spring - MyBatis 在转换 #{} 元素时,出现多余的 '?
- php - 如何将数组转换为 json 对象?
- html - 更改网格视图的方向
- makefile - 使用 msys2 构建 pjsip 2.10
- python - 使用 scipy 的牛顿函数求解方程
- powershell - PowerShell 获取 SharePoint 日历项目
- java - Android studio-当互联网不可用时禁用下载按钮/活动
- firebase - Cloud Functions 未上传 - Firebase
- linux - 我可以在 Debian 中使用 GNAT 社区版 IDE 吗?
- javascript - JS 函数路径中的用户配置文件给出错误,找不到路径