Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 16th, 2004, 06:31 AM
Registered User
 
Join Date: Jan 2004
Location: , , United Kingdom.
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
wrox@cadburyscreamegg.com
__________________
To eMail change cadburyscreamegg.com to colinsteadman.com
wrox@cadburyscreamegg.com
Reply With Quote
  #2 (permalink)  
Old January 16th, 2004, 06:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
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.
Reply With Quote
  #3 (permalink)  
Old January 19th, 2004, 11:51 AM
Registered User
 
Join Date: Jan 2004
Location: , , United Kingdom.
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
wrox@cadburyscreamegg.com
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02: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 10:59 PM



All times are GMT -4. The time now is 05:34 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.