全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3184
推到 Plurk!
推到 Facebook!

利用vbscript來開啟已存在的word檔

答題得分者是:axsoft
synnes
一般會員


發表:14
回覆:12
積分:5
註冊:2002-12-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-01-08 11:47:48 IP:211.75.xxx.xxx 未訂閱
我寫了下列的程式 但出現錯誤訊息為:伺服器丟出一個例外 請問我哪出錯了或者是否有相關的技術能指引我~~謝謝 <% Dim WrdName select Case Request("openfile") Case "te" : wrdName="D:\te.doc" Case "ta" : wrdName="D:ta.doc" End Select set wordObj = Nothing set wordObj = CreateObject("word.Application") wordObj.Documents.open(wrdName) wordObj.visible = true %>
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-01-08 11:59:16 IP:203.73.xxx.xxx 未訂閱
引言: 我寫了下列的程式 但出現錯誤訊息為:伺服器丟出一個例外 請問我哪出錯了或者是否有相關的技術能指引我~~謝謝 <% Dim WrdName select Case Request("openfile") Case "te" : wrdName="D:\te.doc" Case "ta" : wrdName="D:ta.doc" End Select set wordObj = Nothing set wordObj = CreateObject("word.Application") wordObj.Documents.open(wrdName) wordObj.visible = true %>
synnes 你好: 試試以下這個連結
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-01-10 11:41:39 IP:61.218.xxx.xxx 未訂閱
引言: 我寫了下列的程式 但出現錯誤訊息為:伺服器丟出一個例外 請問我哪出錯了或者是否有相關的技術能指引我~~謝謝 <% Dim WrdName select Case Request("openfile") Case "te" : wrdName="D:\te.doc" Case "ta" : wrdName="D:ta.doc" End Select set wordObj = Nothing set wordObj = CreateObject("word.Application") wordObj.Documents.open(wrdName) wordObj.visible = true %>
參考這個試試看: Description: Allows you to run an arbitrary document through the Microsoft Word spelling and grammar checker for interactive correction, either by command line argument or by drag and drop onto the script. It is also suitable for integration into a web document (I have an example of that now). Script: ' Requires Microsoft Word 97 or higher installed ' Comments to alexangelopoulos@hotmail.com ' save as wordcheck.vbs ' files can also be dropped onto the script to spellcheck them. ' The error and optional completion messages are implemented with ' wscript.echo; this allows the script to work correctly even if ' cscript is chosen as the engine for execution. ' Inspired by a spelling-only implementation of an ASP-based checker ' originally done by Anil Parangat. ' Check that 1 and only 1 argument is supplied on the command line ' If not, then exit ' this allows correct operation if used externally Set objArgs = WScript.Arguments if objArgs.length <> 1 Then wscript.echo "Supply the file name as 1 argument." : wscript.quit
    ' Step 1: Read in the TextPad file
strcheckText = strInFileText(objArgs(0))    'Step 2: Fire up the word components and check the text strCheckText = Spelling_Grammar(strCheckText)    'Step 3: Save it back to the file.
WriteFile objArgs(0),strCheckText    'If you want final notification, uncomment the following line 'wscript.echo "Spelling and grammar check of " & objArgs(0) & " done."    Function strInFileText(strFilePath)
     'Given the path to a VBScript file, subImportCodeFile will
     'import it and execute it globally
     Set fso = CreateObject("Scripting.FileSystemObject")
     CONST ForReading = 1, ForWriting = 2
     Dim fso, f
     'get Text file read in
     Set f = fso.OpenTextFile(strFilePath, ForReading)
     strInFileText = f.ReadAll
End Function        Sub modWriteToFile(strToWrite,strFilePath)
     'strToWrite is data written to file strFilePath
     CONST ForReading = 1, ForWriting = 2, ForAppending = 8
     Set objFSO = CreateObject("Scripting.FileSystemObject")
     Set fileRef = objFSO.OpenTextFile(strFilePath, ForAppending, True)
     fileRef.WriteLine(strToWrite)
End Sub        function Spelling_Grammar(TextValue)
     Dim objWord, objDocument, strReturnValue         Set objWord = CreateObject("word.Application")
     objWord.WindowState = 2
     objWord.Visible = False         'Create a new instance of Document
     Set objDocument = objWord.Documents.Add( , , 1, True)
     objDocument.Content=TextValue
     objDocument.CheckSpelling
     objDocument.CheckGrammar         'Return checked text and quit Word
     strReturnValue = objDocument.Content
     objDocument.Close False
     objWord.Application.Quit True         Spelling_Grammar=strReturnValue
End function        Sub WriteFile(strFilePath,strData)
     'Given the path to a VBScript file, subImportCodeFile will
     ' import it and execute it globally
     Set fso = CreateObject("Scripting.FileSystemObject")
     CONST ForReading = 1, ForWriting = 2
     Dim fso, f
     'get Text file read in
     Set f = fso.OpenTextFile(strFilePath, ForWriting)
     f.Write strData
End Sub    
聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]--- 發表人 - axsoft 於 2003/01/10 11:43:00
synnes
一般會員


發表:14
回覆:12
積分:5
註冊:2002-12-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-01-15 08:50:23 IP:211.75.xxx.xxx 未訂閱
我已寫好了此功能,但是在client 端卻不能run 這是什麼原因呢?? 路徑我是設成 c:\tt.doc是這個地方錯嗎???? 還是不是能呢???
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-01-15 12:42:26 IP:61.218.xxx.xxx 未訂閱
引言: 我已寫好了此功能,但是在client 端卻不能run 這是什麼原因呢?? 路徑我是設成 c:\tt.doc是這個地方錯嗎???? 還是不是能呢???
如果您的tt.doc是放在Server端 路徑是不能設成c:\tt.doc 需路徑為 \\Server Name\path name\tt.doc 聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]---
系統時間:2024-05-02 22:26:56
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!