Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing arguments to a word document 2

Status
Not open for further replies.

georgizas

Programmer
Sep 13, 2001
15
GR
I want to pass arguments opening a word document for use with VBA
 
?

For what purpose will you be "passing arguments to a word document"?

*cLFlaVA
----------------------------
When will I be able to see what other members can see about myself? It's been like, a freakin' month already!
 
I need a parameter to get sum data from a database into word document
 
You need to be much more specific when asking questions.

What kind of database? Access? What will the parameter be doing? Do you plan on using VBA code? What version of Word are you using? etc...

*cLFlaVA
----------------------------
When will I be able to see what other members can see about myself? It's been like, a freakin' month already!
 
You can not really pass arguments to the executable of Word. Although you can certainly pass macronames to it.

The alternative is to use VBA code in an AutoOpen sub in a module; the Document_Open event in the ThisDocument module

Either one is very capable of processing what ever you wantto have happen on document open.

Have to agree with cLFlaVA. Exceedingly difficult to makemuch comments, wotjout some details. "Passing arguments" is much too vague.

Gerry
 
I want to construct a word document but I need some details into the body. These details are into a database (SQL Server) so i use VBA in the Document_open event.
I Use ADODB and after the connection to the SQLServer I could get the data but I need value as the primary key. Here is my code:
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim constr
constr = "Provider=sqloledb;Server=MYSERVER;Database=MYDATABASE;UID=myuid;PWD=mypwd;"
cn.Open constr
I plan to construct a document for each record into a table. I have the primary key value in an html(aspx) page but i dont know how can i pass this value into the document.
This is my problem. Isnt enough? Is anybody ho could help me?
 
You are going to have to open (or create) a document, then retrieve that value. Once the document is open it can accept whatever value you pass to it, within legitimate procedures of course. However, I do not know of a way to pass a value to Word BEFORE loading it.

So open the first document.
Query the database for the first record.
Do whatever it is your are doing (you do not say what that is).
Save that document.
Add a new one, get the next record and do what ever it is your are doing.

and so on.

This is from Word.

On the other hand, if you are doing (what ever it is you are doing...which you do not say) it from outside of Word, then you have to create an instance of Word, then process.

Can't really say much else, as "construct a document for each record into a table" still does not say a lot.

Further, it seems the actual problem is getting the primary key from the html(aspx) page, correct? So it is, in fact, THAT value you are trying to get into Word, correct?

You do really have to clearly spell out things, as we are not mind readers.

If the problem is getting data (your primary key) from a web page....say so. Say if that is a file on a local machine, on a local network, out there on a remote web server.

Do you know how to get the value from that page programatically? If so, do it from inside Word. Then in fact you are not "passing" the argument to Word - Word (and VBA) is "getting" the argument.

Since I, for one, am still not clear what the situation is, or what you are trying to do, but it seems somewhat related to getting information from a web page, I suggest you look up some information on sending a WinHTTPRequest. This uses the WinHTTP.DLL library, which MUST be referenced.

I am still unclear, the primary key is on a HTML page, but you have the other values in your SQL DB?

Gerry
 
Yes the primary key is on a HTML page, but I have the other values in my SQL DB.
I found a solution. But i stil have problem.
I wrote a method in the word with a parameter that i need.
I want to open the word doc from aspx, run the method and after that download it from server.
I m sorry for my english. Thank you anyway
 
I wrote a method in the word with a parameter that i need.

Please post some code.

And also please post what did found for a solution.

Thanks.

Gerry
 
This is the method into word:
Public Sub filldoc(p_id As String)
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim constr
constr = "Provider=sqloledb;Server=MYSERVER;Database=MYDB;UID=MYUID;PWD=MYPWD;"
cn.Open constr
...(get the resultset and put the fields into regions inside the body)...
end sub

It works perfect when i try to call ths method with Document_Open method (on Document open event)
But the problem is that i want to do this in my aspx page.
I try to open a new word application in aspx:
Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document
'Create a new instance of Word
objWordApp = New Word.Application()

'Open the document containing the macro
'objWordDoc = _
' objWordApp.Documents.Open("C:\Inetpub\
'Run the macro
objWordDoc.filldoc ("primary_key")

and i get a security error from the server.
 
Two things I notice are 1) that you declare, but never instantiate, your Word Document and 2) you should probably be using the "Set" command.

Code:
Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document

' Create a new instance of Word
Set objWordApp = New Word.Application()
' Create a new word document
Set objWordDoc = objWordApp.Documents.Add()

*cLFlaVA
----------------------------
When will I be able to see what other members can see about myself? It's been like, a freakin' month already!
 
Maybe you should post a link to this question in the ASP forum.

*cLFlaVA
----------------------------
When will I be able to see what other members can see about myself? It's been like, a freakin' month already!
 
Also, is that instance not invisible? If someone is going to work on it, you have to make it visible.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top