Change hardcoded file path to user prompted in VBA?

无人久伴 提交于 2019-12-01 00:01:29

Two ways:

Simple

Dim path As String

path = InputBox("Enter a file path", "Title Here")
Open path For Output As #1
Close #1

With File Chooser

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

You're looking for the InputBox function.

Open InputBox("Enter a file path", "Title", "default path") For Output As #n
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!