Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.beginners
external usenet poster
 
Posts: 87
Default passing variables from excel to word

If I want to open word from excel using automation like this, is there
any way I can pass two variables across - the only way I can think of at
the moment is to use a file in between with the values in!

Sub OpenWord()

Dim oDoc As Word.Document
Dim oWord As Word.Application


'See if word's already running
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
'No, so start a new word session
Set oWord = New Word.Application
Err.Clear
End If

oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Open(ThisWorkbook.Path & "\Envelope.doc")
--
Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default passing variables from excel to word

What are these two variables supposed to be used for in Word? Are they arguments for a Word
macro? Actions to be taken in Word (in that case I think your macro can just carry them out).

On Fri, 18 Jul 2003 23:32:22 +0100, Mike NG wrote:

If I want to open word from excel using automation like this, is there
any way I can pass two variables across - the only way I can think of at
the moment is to use a file in between with the values in!

Sub OpenWord()

Dim oDoc As Word.Document
Dim oWord As Word.Application


'See if word's already running
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
'No, so start a new word session
Set oWord = New Word.Application
Err.Clear
End If

oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Open(ThisWorkbook.Path & "\Envelope.doc")


  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.beginners
external usenet poster
 
Posts: 87
Default passing variables from excel to word

On Sat, 19 Jul 2003 at 08:55:55, John Green (John Green
) wrote:
Mike,

If you are trying to insert data into your Word document, I recommend using document variables.

You can place fields in your document such as {DOCVARIABLE Product}

In your code you can assign values to the variables:

oDoc.Variables("Product") = "Oranges"

While that sounds cool, is there any way of passing variable into the
code section of the VBA in the word document from the code of excel?

I assume that once in the word document, I can read them into the VBA
code, and then set them to null, because I take it that all DOCVARIABLES
in the word document must appear in the page-
--
Mike
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default passing variables from excel to word

On Fri, 18 Jul 2003 at 17:36:19, Myrna Larson (Myrna Larson
) wrote:
What are these two variables supposed to be used for in Word? Are they arguments for a Word
macro?

Yes

It's for passing the queue name of the printer that I want that word
document to temporarily use
--
Mike
  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.beginners
external usenet poster
 
Posts: 3
Default passing variables from excel to word

Hi Mike,

In the Word VBA code, you can use oDoc.Variables('Product") or
oDoc.Variables('Product").Value (though the value is not really necessary
because it is the default property of a Variable. Having does maybe make
the code a bit easier to understand )

The variables do not have to appear anywhere in the document if you don't
want them to, so you can leave the value in them. If you do want to display
the value of the variable in the document, you do so by use of a {
DOCVARIABLE "Product" } field.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Mike NG" wrote in message
...
On Sat, 19 Jul 2003 at 08:55:55, John Green (John Green
) wrote:
Mike,

If you are trying to insert data into your Word document, I recommend

using document variables.

You can place fields in your document such as {DOCVARIABLE Product}

In your code you can assign values to the variables:

oDoc.Variables("Product") = "Oranges"

While that sounds cool, is there any way of passing variable into the
code section of the VBA in the word document from the code of excel?

I assume that once in the word document, I can read them into the VBA
code, and then set them to null, because I take it that all DOCVARIABLES
in the word document must appear in the page-
--
Mike





  #6   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.beginners
external usenet poster
 
Posts: 87
Default passing variables from excel to word

On Sat, 19 Jul 2003 at 20:22:32, Doug Robbins - Word MVP (Doug Robbins -
Word MVP ) wrote:
In the Word VBA code, you can use oDoc.Variables('Product") or
oDoc.Variables('Product").Value (though the value is not really necessary
because it is the default property of a Variable. Having does maybe make
the code a bit easier to understand )

The variables do not have to appear anywhere in the document if you don't
want them to, so you can leave the value in them. If you do want to display
the value of the variable in the document, you do so by use of a {
DOCVARIABLE "Product" } field.

OK thanks - I will give that a go some time soon - just been away for a
long weekened
--
Mike
  #7   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.beginners
external usenet poster
 
Posts: 87
Default passing variables from excel to word

On Sat, 19 Jul 2003 at 20:22:32, Doug Robbins - Word MVP (Doug Robbins -
Word MVP ) wrote:
In the Word VBA code, you can use oDoc.Variables('Product") or
oDoc.Variables('Product").Value (though the value is not really necessary
because it is the default property of a Variable. Having does maybe make
the code a bit easier to understand )

The variables do not have to appear anywhere in the document if you don't
want them to, so you can leave the value in them. If you do want to display
the value of the variable in the document, you do so by use of a {
DOCVARIABLE "Product" } field.

I seem to be having some sort of synchronisation problem. This is my
excel code

Sub OpenWord()

Dim oDoc As Word.Document
Dim oWord As Word.Application


'See if word's already running
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
'No, so start a new word session
Set oWord = New Word.Application
Err.Clear
End If

oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Open(ThisWorkbook.Path & "\Envelope.doc")
oDoc.Variables("Product") = "HELLO WORLD"
Set oWord = Nothing
Set oDoc = Nothing

End Sub



This is a simplified version of my word document open event

Private Sub Document_Open()

MsgBox "" & ThisDocument.Variables("Product") & "<<"

End Sub


However, when word opens, it tells me the object has been deleted
--
Mike
  #8   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.beginners
external usenet poster
 
Posts: 3
Default passing variables from excel to word

HI Mike,

How about if you include

oDoc.Save

before setting things to nothing.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Mike NG" wrote in message
...
On Sat, 19 Jul 2003 at 20:22:32, Doug Robbins - Word MVP (Doug Robbins -
Word MVP ) wrote:
In the Word VBA code, you can use oDoc.Variables('Product") or
oDoc.Variables('Product").Value (though the value is not really necessary
because it is the default property of a Variable. Having does maybe make
the code a bit easier to understand )

The variables do not have to appear anywhere in the document if you don't
want them to, so you can leave the value in them. If you do want to

display
the value of the variable in the document, you do so by use of a {
DOCVARIABLE "Product" } field.

I seem to be having some sort of synchronisation problem. This is my
excel code

Sub OpenWord()

Dim oDoc As Word.Document
Dim oWord As Word.Application


'See if word's already running
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
'No, so start a new word session
Set oWord = New Word.Application
Err.Clear
End If

oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Open(ThisWorkbook.Path & "\Envelope.doc")
oDoc.Variables("Product") = "HELLO WORLD"
Set oWord = Nothing
Set oDoc = Nothing

End Sub



This is a simplified version of my word document open event

Private Sub Document_Open()

MsgBox "" & ThisDocument.Variables("Product") & "<<"

End Sub


However, when word opens, it tells me the object has been deleted
--
Mike



  #9   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.beginners
external usenet poster
 
Posts: 87
Default passing variables from excel to word

On Tue, 22 Jul 2003 at 16:26:13, Doug Robbins - Word MVP (Doug Robbins -
Word MVP ) wrote:
HI Mike,

How about if you include

oDoc.Save

before setting things to nothing.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

No that didn't work. Now I've got my default printer working (see other
thread), I'm not so bothered about this now, but it has got me
intrigued.
--
Mike
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA - passing Variables to subroutines Madduck Excel Discussion (Misc queries) 12 September 19th 08 03:20 AM
Passing Variables Jeff Excel Discussion (Misc queries) 1 November 4th 05 06:46 PM
VBA passing variables through a function Jeff Excel Discussion (Misc queries) 2 November 3rd 05 11:23 PM
Passing variables between a form and macro David New Users to Excel 1 October 5th 05 04:42 AM
Passing variables between a form and macro David New Users to Excel 4 September 23rd 05 11:57 AM


All times are GMT +1. The time now is 06:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"