[VBScript]Open File Dialog 開啟檔案的對話方塊
前言:
最近在做專案時,需要使用到File Dialog來取得使用者要儲存的位置和檔名。
但在G大神搜尋到的都是使用UserAccounts.CommonDialog的方式,這個方式有個缺點(致命的缺點)就是只有Winxp才能使用。
後來才找到另外一個 MSComDlg.CommonDialog的方式,終於可以使用在Win7。但是它是使用comdlg32.OCX的ActiveX方式執行,所以必須要有此元件。這個元件呢,是只有安裝VB6或
vb6編譯完成的程式才可以(此物件除了系統註冊外還必須要授權)。(有在後面找到註冊的方法,但是必須要真的擁有vb6的軟體授權才能使用)
先來講解一下UserAccounts.CommonDialog的程式部分
在XP上使用的話的畫面如下:
非WinXP的畫面(無法執行的錯誤畫面)
MSComDlg.CommonDialog的程式部分
執行失敗畫面一(未安裝comdlg32.ocx)
-----待補相片-----
執行失敗畫面二(元件未授權)
-----待補相片-----
元件註冊部分:
-----待補說明及相片-----
元件授權部分(注意:此方式必須擁有vb6的軟體授權才能使用,否則為盜版行為):
將下列的的註冊機碼加入到電腦中即可
===========================================================================
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Licenses\12B142A4-BD51-11d1-8C08-0000F8754DA1]
@="aadhgafabafajhchnbchehfambfbbachmfmb"
[HKEY_CLASSES_ROOT\Licenses\190B7910-992A-11cf-8AFA-00AA00C00905]
@="gclclcejjcmjdcccoikjlcecoioijjcjnhng"
[HKEY_CLASSES_ROOT\Licenses\1F3D5522-3F42-11d1-B2FA-00A0C908FB55]
@="gcfjdjecpchcncdjpdejijgcrdoijjfcieod"
[HKEY_CLASSES_ROOT\Licenses\2c49f800-c2dd-11cf-9ad6-0080c7e7b78d]
@="mlrljgrlhltlngjlthrligklpkrhllglqlrk"
[HKEY_CLASSES_ROOT\Licenses\4250E830-6AC2-11cf-8ADB-00AA00C00905]
@="kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\4D553650-6ABE-11cf-8ADB-00AA00C00905]
@="gfjmrfkfifkmkfffrlmmgmhmnlulkmfmqkqj"
[HKEY_CLASSES_ROOT\Licenses\4F86BADF-9F77-11d1-B1B7-0000F8753F5D]
@="iplpwpnippopupiivjrioppisjsjlpiiokuj"
[HKEY_CLASSES_ROOT\Licenses\57CBF9E0-6AA7-11cf-8ADB-00AA00C00905]
@="aahakhchghkhfhaamghhbhbhkbpgfhahlfle"
[HKEY_CLASSES_ROOT\Licenses\6FB38640-6AC7-11cf-8ADB-00AA00C00905]
@="gdjkokgdldikhdddpjkkekgknesjikdkoioh"
[HKEY_CLASSES_ROOT\Licenses\72E67120-5959-11cf-91F6-C2863C385E30]
@="ibcbbbebqbdbciebmcobmbhifcmciibblgmf"
[HKEY_CLASSES_ROOT\Licenses\78E1BDD1-9941-11cf-9756-00AA00C00908]
@="yjrjvqkjlqqjnqkjvprqsjnjvkuknjpjtoun"
[HKEY_CLASSES_ROOT\Licenses\7C35CA30-D112-11cf-8E72-00A0C90F26F8]
@="whmhmhohmhiorhkouimhihihwiwinhlosmsl"
[HKEY_CLASSES_ROOT\Licenses\80E80EF0-DBBE-11D0-BCE2-00A0C90DCA10]
@="qijimitpmpnpxplpvjnikpkpqoxjmpkpoivj"
[HKEY_CLASSES_ROOT\Licenses\899B3E80-6AC6-11cf-8ADB-00AA00C00905]
@="wjsjjjlqmjpjrjjjvpqqkqmqukypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\9E799BF1-8817-11cf-958F-0020AFC28C3B]
@="uqpqnqkjujkjjjjqwktjrjkjtkupsjnjtoun"
[HKEY_CLASSES_ROOT\Licenses\B1EFCCF0-6AC1-11cf-8ADB-00AA00C00905]
@="qqkjvqpqmqjjpqjjvpqqkqmqvkypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\BC96F860-9928-11cf-8AFA-00AA00C00905]
@="mmimfflflmqmlfffrlnmofhfkgrlmmfmqkqj"
[HKEY_CLASSES_ROOT\Licenses\CDE57A55-8B86-11D0-b3C6-00A0C90AEA82]
@="ekpkhddkjkekpdjkqemkfkldoeoefkfdjfqe"
[HKEY_CLASSES_ROOT\Licenses\DC4D7920-6AC8-11cf-8ADB-00AA00C00905]
@="iokouhloohrojhhhtnooiokomiwnmohosmsl"
[HKEY_CLASSES_ROOT\Licenses\E32E2733-1BC5-11d0-B8C3-00A0C90DCA10]
@="kmhfimlflmmfpffmsgfmhmimngtghmoflhsg"
[HKEY_CLASSES_ROOT\Licenses\ED4B87C4-9F76-11d1-8BF7-0000F8754DA1]
@="knlggnmntgggrninthpgmnngrhqhnnjnslsh
===========================================================================
程式碼參考網址:
UserAccounts.CommonDialog
http://www.robvanderwoude.com/vbstech_ui_fileopen.php
MSComDlg.CommonDialog
http://www.win7dll.info/comctl32_dll.html
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/bd96d326-59f2-42b0-b04d-4ed65c4ce692
註冊機碼參考網址:
http://gzkhrh.blog.51cto.com/30447/294886
最近在做專案時,需要使用到File Dialog來取得使用者要儲存的位置和檔名。
但在G大神搜尋到的都是使用UserAccounts.CommonDialog的方式,這個方式有個缺點(致命的缺點)就是只有Winxp才能使用。
後來才找到另外一個 MSComDlg.CommonDialog的方式,終於可以使用在Win7。但是它是使用comdlg32.OCX的ActiveX方式執行,所以必須要有此元件。這個元件呢,是只有安裝VB6或
vb6編譯完成的程式才可以(此物件除了系統註冊外還必須要授權)。(有在後面找到註冊的方法,但是必須要真的擁有vb6的軟體授權才能使用)
先來講解一下UserAccounts.CommonDialog的程式部分
' Standard housekeeping Dim objDialog ' Create a dialog object Set objDialog = CreateObject( "UserAccounts.CommonDialog" ) ' Check arguments and use defaults when necessary 'If myDir = "" Then ' Default initial folder is "My Documents" ' objDialog.InitialDir = CreateObject( "WScript.Shell" ).SpecialFolders( "MyDocuments" ) 'Else ' Use the specified initial folder objDialog.InitialDir = "c:\" 'End If If myFilter = "" Then ' Default file filter is "All files" objDialog.Filter = "All files|*.*" Else ' Use the specified file filter objDialog.Filter = myFilter End If ' Open the dialog and return the selected file name If objDialog.ShowOpen Then GetFileName = objDialog.FileName Else GetFileName = "" End If msgbox GetFileName
在XP上使用的話的畫面如下:
非WinXP的畫面(無法執行的錯誤畫面)
MSComDlg.CommonDialog的程式部分
Dim objDialog Set objDialog = CreateObject("MSComDlg.CommonDialog") With objDialog .Filter = "*.PDF" .InitDir = "C:" .MaxFileSize = 256 '.Flags = &H80000 + &H4 + &H8 End With objDialog.ShowSave If objDialog.FileName<>"" Then i=Len(objDialog.FileName) '計算字串長度 '判斷檔名是否包含副檔名 If UCase(Mid(objDialog.FileName,i-3,i))=".PDF" Then Alarm_Save_PDF_FileName=objDialog.FileName Else Alarm_Save_PDF_FileName=objDialog.FileName & ".pdf" End If msgbox Alarm_Save_PDF_FileName Else msgbox "Nothing" End If正常的執行畫面如下(在一台有安裝VB6的電腦上執行)
執行失敗畫面一(未安裝comdlg32.ocx)
-----待補相片-----
執行失敗畫面二(元件未授權)
-----待補相片-----
元件註冊部分:
-----待補說明及相片-----
元件授權部分(注意:此方式必須擁有vb6的軟體授權才能使用,否則為盜版行為):
將下列的的註冊機碼加入到電腦中即可
===========================================================================
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Licenses\12B142A4-BD51-11d1-8C08-0000F8754DA1]
@="aadhgafabafajhchnbchehfambfbbachmfmb"
[HKEY_CLASSES_ROOT\Licenses\190B7910-992A-11cf-8AFA-00AA00C00905]
@="gclclcejjcmjdcccoikjlcecoioijjcjnhng"
[HKEY_CLASSES_ROOT\Licenses\1F3D5522-3F42-11d1-B2FA-00A0C908FB55]
@="gcfjdjecpchcncdjpdejijgcrdoijjfcieod"
[HKEY_CLASSES_ROOT\Licenses\2c49f800-c2dd-11cf-9ad6-0080c7e7b78d]
@="mlrljgrlhltlngjlthrligklpkrhllglqlrk"
[HKEY_CLASSES_ROOT\Licenses\4250E830-6AC2-11cf-8ADB-00AA00C00905]
@="kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\4D553650-6ABE-11cf-8ADB-00AA00C00905]
@="gfjmrfkfifkmkfffrlmmgmhmnlulkmfmqkqj"
[HKEY_CLASSES_ROOT\Licenses\4F86BADF-9F77-11d1-B1B7-0000F8753F5D]
@="iplpwpnippopupiivjrioppisjsjlpiiokuj"
[HKEY_CLASSES_ROOT\Licenses\57CBF9E0-6AA7-11cf-8ADB-00AA00C00905]
@="aahakhchghkhfhaamghhbhbhkbpgfhahlfle"
[HKEY_CLASSES_ROOT\Licenses\6FB38640-6AC7-11cf-8ADB-00AA00C00905]
@="gdjkokgdldikhdddpjkkekgknesjikdkoioh"
[HKEY_CLASSES_ROOT\Licenses\72E67120-5959-11cf-91F6-C2863C385E30]
@="ibcbbbebqbdbciebmcobmbhifcmciibblgmf"
[HKEY_CLASSES_ROOT\Licenses\78E1BDD1-9941-11cf-9756-00AA00C00908]
@="yjrjvqkjlqqjnqkjvprqsjnjvkuknjpjtoun"
[HKEY_CLASSES_ROOT\Licenses\7C35CA30-D112-11cf-8E72-00A0C90F26F8]
@="whmhmhohmhiorhkouimhihihwiwinhlosmsl"
[HKEY_CLASSES_ROOT\Licenses\80E80EF0-DBBE-11D0-BCE2-00A0C90DCA10]
@="qijimitpmpnpxplpvjnikpkpqoxjmpkpoivj"
[HKEY_CLASSES_ROOT\Licenses\899B3E80-6AC6-11cf-8ADB-00AA00C00905]
@="wjsjjjlqmjpjrjjjvpqqkqmqukypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\9E799BF1-8817-11cf-958F-0020AFC28C3B]
@="uqpqnqkjujkjjjjqwktjrjkjtkupsjnjtoun"
[HKEY_CLASSES_ROOT\Licenses\B1EFCCF0-6AC1-11cf-8ADB-00AA00C00905]
@="qqkjvqpqmqjjpqjjvpqqkqmqvkypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\BC96F860-9928-11cf-8AFA-00AA00C00905]
@="mmimfflflmqmlfffrlnmofhfkgrlmmfmqkqj"
[HKEY_CLASSES_ROOT\Licenses\CDE57A55-8B86-11D0-b3C6-00A0C90AEA82]
@="ekpkhddkjkekpdjkqemkfkldoeoefkfdjfqe"
[HKEY_CLASSES_ROOT\Licenses\DC4D7920-6AC8-11cf-8ADB-00AA00C00905]
@="iokouhloohrojhhhtnooiokomiwnmohosmsl"
[HKEY_CLASSES_ROOT\Licenses\E32E2733-1BC5-11d0-B8C3-00A0C90DCA10]
@="kmhfimlflmmfpffmsgfmhmimngtghmoflhsg"
[HKEY_CLASSES_ROOT\Licenses\ED4B87C4-9F76-11d1-8BF7-0000F8754DA1]
@="knlggnmntgggrninthpgmnngrhqhnnjnslsh
===========================================================================
程式碼參考網址:
UserAccounts.CommonDialog
http://www.robvanderwoude.com/vbstech_ui_fileopen.php
MSComDlg.CommonDialog
http://www.win7dll.info/comctl32_dll.html
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/bd96d326-59f2-42b0-b04d-4ed65c4ce692
註冊機碼參考網址:
http://gzkhrh.blog.51cto.com/30447/294886
留言
張貼留言