从MS Word文档复制到网页输入框

时间:2010-09-28 08:52:45

标签: ms-word word-vba

在已打开的word文档中选择所有文本
将所选文本复制到剪贴板
检查默认浏览器是否在正确的网址上打开     如果没有在网址“http://thisaddress.com”打开默认浏览器 把重点放在浏览器上 将剪贴板文本粘贴到名为“input1”

的输入框中

或将MSword文档内容输入网页输入的其他方式?

目前,工作流程涉及秘书登录网站,然后填写网络表单,切换到打开的MS Word文档,选择全部,复制WP文档,然后返回到Web表单并粘贴到输入框中,然后点击提交。我想要做的事情理想情况下在MS word中有一个按钮,它将浏览器打开到正确的网页,然后将文档复制并粘贴到页面上正确的输入框中(实际上它将是唯一的textarea表单字段)。

MS Word VBA代码是:

Option Explicit

Enum W32_Window_State
    Show_Normal = 1
    Show_Minimized = 2
    Show_Maximized = 3
    Show_Min_No_Active = 7
    Show_Default = 10
End Enum

Private Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" (ByVal hWnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, _
    ByVal lpParameters As String, ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

Function OpenURL(URL As String, WindowState As W32_Window_State) As Boolean

' Opens passed URL with default application, or Error Code (<32) upon error

    Dim lngHWnd As Long
    Dim lngReturn As Long

    lngReturn = ShellExecute(lngHWnd, "open", URL, vbNullString, _
        vbNullString, WindowState)

    OpenURL = (lngReturn > 32)
End Function

Sub TestMacro()
  Application.ActiveDocument.Select
  Selection.Copy
  OpenURL "http://localhost:8500/index.cfm?wordContent=" & Selection, W32_Window_State.Show_Maximized
End Sub

和冷融处理表格

<html>
<head>
</head>

<body>
<form id="form1">
    <Textarea ID="txtArea" rows=6><cfoutput>#url.wordContent#</cfoutput></textarea>
</form>

</body>
</html>

我想知道如果一个浏览器窗口已经打开,如何不打开它。

2 个答案:

答案 0 :(得分:2)

如果您可以修改网络应用程序,您可以执行以下操作:

  1. MS-Word:将内容复制到剪贴板。
  2. MS-Word:打开网址为“http://thisaddress.com/SomePage?pasteClipboard=true”
  3. SomePage:如果query-string param pasteClipboard == true,则添加一个javascript函数,将剪贴板数据放入表单域。
  4. <强>更新

    在您的微距中,您只需致电Selection.Copy,然后使用默认浏览器打开网址,请点击此链接http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23225744.html

    使用上一个链接中的代码,我将测试宏设为:

    Sub TestMacro()
      Application.ActiveDocument.Select
      Selection.Copy
      OpenURL  "http://thisaddress.com/SomePage?pasteClipboard=true", W32_Window_State.Show_Maximized
    End Sub
    

    我希望这很有帮助。

    更新2:

    只需使用W32_Window_State.Show_Default,这是完整的宏:

    Option Explicit
    
    Enum W32_Window_State
        Show_Normal = 1
        Show_Minimized = 2
        Show_Maximized = 3
        Show_Min_No_Active = 7
        Show_Default = 10
    End Enum
    
    Private Declare Function ShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" (ByVal hWnd As Long, _
        ByVal lpOperation As String, ByVal lpFile As String, _
        ByVal lpParameters As String, ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) As Long
    
    Function OpenURL(URL As String, WindowState As W32_Window_State) As Boolean
    
    ' Opens passed URL with default application, or Error Code (<32) upon error
    
        Dim lngHWnd As Long
        Dim lngReturn As Long
    
        lngReturn = ShellExecute(lngHWnd, "open", URL, vbNullString, _
            vbNullString, WindowState)
    
        OpenURL = (lngReturn > 32)
    End Function
    
    Sub TestMacro()
      Application.ActiveDocument.Select
      Selection.Copy
      OpenURL "http://thisaddress.com/SomePage?pasteClipboard=true", W32_Window_State.Show_Default
    End Sub
    

答案 1 :(得分:0)

另一种选择是使用控件从Word内部控制Internet Explorer。

Here就是一个例子。

注意,这只适用于IE(除非有dll版本的Firefox等。)