GetOpenFilename释放内存 VBA中如何用GetOpenFilename获取到文件名?

VBA中如何用GetOpenFilename获取到文件名?Private sub CommandButtonuclick()Dim strfile As String strfile=Applicat

VBA中如何用GetOpenFilename获取到文件名?

Private sub CommandButtonuclick()Dim strfile As String strfile=Application.GetOpenFilename(“所有文件(*。*), *. *)如果strFile=“false”,则“strFile定义字符串类型,不能与布尔类型false进行比较。Msgbox(“no document selected”)exit sub else“如果strFile为false,则Msgbox(strFile)end IfEnd sub

成功执行GetOpenFilename后,您可以使用函数pathstrippath获取文件名。openfilenameonfcharstrfile[MAX_u2;PATH]memset(&ofn,0,sizeof(OPENFILENAME))memset(strFile,0,sizeof(char)*MAX_2;PATH)ofn.lStructSize=大小(OPENFILENAME)ofn.lpstrFilter=“网页(。HTML)0*。HTML格式**。HTM*0“ofn.lpstrFile=strFileofn.nMaxFile=最大uPATHofn.Flags=OFNuFilemultistatif(GetOpenFilename(&stfile))//strFile获取用户选择的文件的路径和文件名{pathstrippath(strFile)//strFile获取文件名}