
VBScript - Using Word / Office Macros
<%
Dim oWord, oWDoc
Set oWord = Server.CreateObject ("Word.Application")
With oWord
Set oWDoc = .Documents.Open (Server.MapPath (("d:\temp\Wordtest.doc"))
.Run "Macro1"
End With
With oWDoc
.PrintOut False
.Save
End With
Set oWDoc = Nothing
Set oWord = Nothing
%>
<
Try that.
--
Dominic
Read The Docs? http://msdn.microsoft.com/scripting
Quote:
> Hi,
> Thanks again for your reply.
> However, I still cannot open (or access) a Word document.
> This is the code I'm using:
> Set WordApp = CreateObject("Word.Application")
> Set WordDoc = WordApp.Documents.Open ("d:\temp\Wordtest.doc") 'the
file
> location on the server
> WordApp.Visible = True 'does nothing (?)
> WordApp.Run "Macro1" 'doesn't run the macro (?)
> WordDoc.PrintOut 'Background:=False 'does not print the document (?)
> WordDoc.Save 'does not save the file
> Set WordApp = Nothing
> Microsoft office is installed on the server. Do I need to install another
> component to make this code work ?
> 10x,
> Ran
> > Surely you can translate simple VBA code to VBScript ;-)...
> > What I gave you in that reply was sufficient to show you how to do what
> you asked.
> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > --
> > > Hi,
> > > I'm posting this question again, since the reply I've got used VBA and
I
> > > meant VBScript.
> > > So here it is:
> > > 1. Is there a way of calling VB functions that are found within a Word
/
> > > Office
> > > document ("Macro") using ASP / VBScript, assuming the file is found on
> the
> > > server side.
> > > Example:
> > > Let's say there is a Word document found on the server.
> > > This document has one variable called UserName.
> > > Whenever a user wants to download a file, prior of downloading it, I
> want to
> > > set this variable to a new value (current user name).
> > > Is it possible ?
> > > Is it possible doing it without opening the file (Word document) ?
> > > How do I refer to a specific document ?
> > > 2. Is there a way of adding code / Macro to a Word / other office
> document.
> > > Again, using VBScript.
> > > Regards,
> > > Ran Chen,