现在,我有一个用于 Word 的 VBA 宏,它可以解析文档中的某种字体,并将所选类型的所有字体输出到文本文件。
我打开文本文件的硬编码行是这样的:
Open "C:\Documents and Settings\Output.txt" For Output As #n
我可以更改此设置,以便提示用户此时在宏中输入文件路径吗?就像是:
Open (PROMPTS USER FOR FILE PATH HERE) For Output As #n
抱歉,如果这看起来微不足道。我是 VBA 编码新手。
两种方式:
Simple
Dim path As String
path = InputBox("Enter a file path", "Title Here")
Open path For Output As #1
Close #1
带文件选择器
Dim path As String
With Application.FileDialog(msoFileDialogOpen)
.Show
If .SelectedItems.Count = 1 Then
path = .SelectedItems(1)
End If
End With
If path <> "" Then
Open path For Output As #n
End If
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)