passing values to a WORD-object

J

Jan Hendrickx

Hi all,

From a HTML-page I use following code to create a new word-document :

Set oWord = CreateObject("Word.Application")
oWord.Documents.Add("C:\Map1\Doc1.dot")
oWord.Visible = True
oWord.Activate
oWord.Run "Test1"

The last line runs a procedure that is stored in the documents module
(Module1)
Before running that last line, I want to pass a value to a variable that
is declared in the same module.

This is 'Module1':

Public sText1 As String
Public Sub Test1
msgbox sText1
End Sub

The help-files show that I could also use oWord.Run "SubName", var1, var2,
var3, ...
but I can't get that to work!!!
I also tried things like 'oWord.sText1="abcde"' or
'oWord.Module1.sText1="abcde"'
but that doesn't work either...

Any hints???

Thanx in advance
Jan Hendrickx
 
H

Helmut Weber

Hi Jan,

without paying much attention to where the sub is stored.
Here I am using a reference to the word-library,
(extras references, ...), which may be not necessary.
But there are many ways, and at least, this is not
your problem.

' Excel ---------------------------------------------
Sub SendFromExcel()
Dim oWrd As Word.Application
Set oWrd = GetObject(, "Word.Application")
oWrd.Visible = True
oWrd.Run "ReceivefromExcel", "Var1", "Var2" ' !!!
End Sub

'Word ---------------------------------------------
Sub ReceiveFromExcel(v1 As String, v2 As String)
MsgBox "v1 = " & v1 & " v2 = " & v2
End Sub


Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top