Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 16th, 2004, 07:31 AM
Registered User
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to colinsteadman
Default Pass variable from ASP to MS Word 2000

I have an ASP powered intranet site that allows users to search for and display basic details about employees. What I want to do now is add a button to the site which would allow the user to generate standard documents for the selected employee in Microsoft Word.

For this to work I need something in ASP which can open a specific document or template on the users PC, start a macro in that template and pass it a variable (employee_number).

Is this possible? And does anyone have any exmaple scripts?

This is what I've got so far using a sample from Microsoft. It works but I cant figure out how to pass the variable to the template:

<html>
<head>
<title>Start Word Template Test</title>
<script language=vbscript>
  Dim objWord

  Sub button_onclick()
    Call OpenDoc("http://server.domain.net/personnel/template.dot")
  End Sub

  Sub OpenDoc(strLocation)
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = true
    objWord.Documents.Open strLocation
  End Sub
</script>
</head>

<body>

<input type=button name=button value="Create Letter">

</body>
</html>

TIA,

Colin

To eMail change cadburyscreamegg.com to colinsteadman.com
[email protected]
 
Old January 16th, 2004, 07:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

check out http://www.greggriffiths.org/webdev/both/excel/ which covers this kind of thing using Excel rather than Word, but the content and the links should give you a headstart.
 
Old January 19th, 2004, 12:51 PM
Registered User
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to colinsteadman
Default

I believe I'm being thwarted by a security protocol somewhere, that is blocking certain script requests. Using your example I've changed the script in my ASP page to the following:

  Sub OpenDoc(strLocation)
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = true
    objWord.Documents.Open strLocation
    objWord.ActiveDocument.Variables("testVar").Value = "testdata"
  End Sub

As before my template opens on the click of the button and the AutoOpen macro in the template fires. However when it processes this line (in the template now):

  MsgBox ActiveDocument.Variables("testVar").Value

I get the original value of testVar, not the new value passed from ASP. However, if I manually run the AutoOpen macro again, I do see the new value so my ASP script is definitely updating it. This is what must be happening:

  objWord.Documents.Open strLocation
    <<< AutoOpen macro running here before variable gets updated >>>
  objWord.ActiveDocument.Variables("testVar").Value = "testdata"

I have therefore changed the ASP script again as follows:

  Sub OpenDoc(strLocation)
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = true
    objWord.Documents.Open strLocation
    objWord.ActiveDocument.Variables("testVar").Value = "testdata"
    objWord.ActiveDocument.Application.Run MacroName:="refreshVar"
  End Sub

The last line here should fire a macro in the template called refreshVar which is exactly the same as AutoOpen. I've tested the code from another Word document and it worked fine. However when I try it in ASP, it breaks the script. When I press the button now, absolutely nothing happens.

Any idea's how I might get round this? I can see two options myself, never of which I favor. The first is to put a button in the template document itself called 'Click here to start' and have that button call my main template macro. Not exactly the elegant solution I'm trying to achieve though. The second option which isn't so bad, is to get all the data I need for the letter and pass it to the template using lots of these commands:

    objWord.ActiveDocument.Variables("testVar").Value = "testdata"

which I already know works. And then see if I can refresh the document in my ASP script.

TIA,

Colin


To eMail change cadburyscreamegg.com to colinsteadman.com
[email protected]





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass XSL variable back to asp.net page ayamas XSLT 8 September 14th, 2006 06:07 AM
VBScript - Sql Server 2000 - MS Word delight_ravi VBScript 0 December 24th, 2004 03:52 AM
Help with VBA (MS Word 2000) vb_programmer Beginning VB 6 0 May 22nd, 2004 12:26 AM
How to use ASP and MS SQL 2000 eapsokha Classic ASP Professional 2 February 26th, 2004 11:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.