WPS JS macro file dialog FileDialog calling method:
Application.FileDialog(FileDialogType)
FileDialogType dialog type MsoFileDialogType.
MsoFileDialogType enumeration type:
- msoFileDialogFilePicker: File Picker dialog box.
- msoFileDialogFolderPicker: Folder Picker dialog box.
- msoFileDialogOpen: "Open" dialog box.
- msoFileDialogSaveAs: "Save As" dialog box.
The calling code example is as follows:
/*该示例显示“另存为”对话框。*/
function ShowSaveAsDialog() {
let dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)
dlgSaveAs.Show()
}
/*本示例显示“打开”对话框并允许用户选择打开多个文件。*/
function ShowFileDialog() {
let dlgOpen = Application.FileDialog(msoFileDialogOpen)
dlgOpen.AllowMultiSelect = true
dlgOpen.Show()
}
In addition, the method to set the default path to open the folder is as follows:
Filedlg.InitialFileName = ThisWorkbook.Path;//The path of the currently active document. (excel)
Filedlg.InitialFileName = ActiveDocument.Path;//The path of the current active document. (word)
let Filedlg = Application.FileDialog(msoFileDialogFilePicker);
Filedlg.InitialFileName = ThisWorkbook.Path;//文件打开位置,设置为当前文档的活动目录
//Filedlg.InitialFileName = 'D:\\';
Filedlg.Show();
By setting InitialFileName, you can specify the location of the default open directory.