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

发布于 2024-09-24 21:12:52 字数 1760 浏览 1 评论 0原文

在已打开的 Word 文档中选择所有文本
将选定的文本复制到剪贴板
检查在正确的网址上打开的默认浏览器
如果未打开默认浏览器,网址为“http://thisaddress.com
将焦点交给浏览器 将剪贴板文本粘贴到名为“input1”的输入框中

,或者以其他方式将 MSword 文档内容获取到网页输入?

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

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

在 Coldfusion 处理表单中

<html>
<head>
</head>

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

</body>
</html>

只是想弄清楚如何在已经打开的浏览器窗口中不打开新的浏览器窗口。

In an already open word document select all text
copy selected text to clipboard
check default browser open at correct web address
if not open default browser at web address "http://thisaddress.com"
give focus to browser
paste clipboard text into input box called "input1"

or some other way to get MSword document contents to a web page input?

Currently the workflow involves a secretary logging in to the website, then filling out a web form, switching to their open MS Word document, selecting all, copying the WP document, then back to the web form and pasting into an input box, then hitting submit. What I want to do ideally have a button in MS word which opens the browser to the correct web page then copies and pastes the document into the correct input box on the page (in fact it will be the only textarea form field).

The MS Word VBA code is:

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

and in the coldfusion handling form

<html>
<head>
</head>

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

</body>
</html>

Just would like to work out how to not open a new browser window if one is already open.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄情伤 2024-10-01 21:12:52

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

  1. MS-Word:将内容复制到剪贴板。
  2. MS-Word:打开网址为“http://thisaddress.com/SomePage?pasteClipboard=true”
  3. SomePage:如果查询字符串参数pasteClipboard == true,则添加一个javascript函数以将剪贴板数据获取到表单字段中。

更新:

在宏中,您只需调用Selection.Copy,并使用默认浏览器打开URL,请检查此链接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

In case you can modify the web-application, you may do the following:

  1. MS-Word: Copy content to clipboard.
  2. MS-Word: Open Url as "http://thisaddress.com/SomePage?pasteClipboard=true"
  3. SomePage: if query-string param pasteClipboard == true, then add a javascript function to get the clipboard data into your form field.

Update:

In your macro you simply call Selection.Copy, and to open the URL using default browser check this link http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23225744.html

Using the code from the previous link, I made a test macro as :

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

I hope this was helpful.

Update 2:

Just use W32_Window_State.Show_Default, Here is the full macro:

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
半窗疏影 2024-10-01 21:12:52

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

这里是一个示例。

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

Another option is to look into controlling Internet Explorer from inside Word using a control.

Here is an example.

Note, this will only work with IE (unless there are dll versions of Firefox etc.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文