Declaring Public Variables from Another Program (Word 2007)

  • Thread starter Karl E. Peterson
  • Start date
K

Karl E. Peterson

LA said:
I want to declare a Public Variable in Word 2007 from another program (in
this case, Access 2007). How is this done?

With a FOIA request?

Only partly in jest. Don't think this is gonna happen. Unless you can
articulate a bit clearer what you're trying to do.
 
L

LA Lawyer

I want to declare a Public Variable in Word 2007 from another program (in
this case, Access 2007). How is this done?
 
K

Karl E. Peterson

LA said:
If I was doing this in Word, I would do something like:
Public Constant NameOfContact as String = "John Smith"

Yeah, me too. But what's the bit about doing it in Word "from" another
program? That just doesn't make sense. I think you need to describe
the goal, not the approach you think may be needed to meet the goal.
 
L

LA Lawyer

If I was doing this in Word, I would do something like:
Public Constant NameOfContact as String = "John Smith"
 
K

Karl E. Peterson

LA said:
I want to assign some variables in Access, then open Word and have those
variables available to me the entire time that I am in that session of Word,
even if open another document.

Are you attempting to automate Word from Access? Or are you just
starting Word up, and wanting it to bootstrap these values somehow?
 
K

Karl E. Peterson

LA said:
The latter: I am starting Word through Access VBA and then I want to use
those values in Word throughout the session, even if I left the
ActiveDocument.

In that case, I'd highly recommend you look at some form of cached
persistence. Maybe writing the values to an INI file or Registry key
that both applications are aware of?

If those aren't viable answers, for some reason or another, we could
look at some totally hacky possibilities. (Like sending Word bogus
command line arguments, then reading those with the API.) But staying
conventional will be a happier path to follow, if you can.
 
L

LA Lawyer

I want to assign some variables in Access, then open Word and have those
variables available to me the entire time that I am in that session of Word,
even if open another document.
 
L

LA Lawyer

The latter: I am starting Word through Access VBA and then I want to use
those values in Word throughout the session, even if I left the
ActiveDocument.
 
L

LA Lawyer

I have been trying, at the same time, to use custom and builtin properties
from Access (automating Word) as follows (this doesn't give me an error
message; it simply doesn't work):

Public Function AddWordCustomProperty(NameofCustomProperty As String,
ValueofCustomProperty As String, Optional TypeOfVariableIfNotString As
String)
Select Case TypeOfVariableIfNotString
Case "Boolean"
TypeOfVariableIfNotString = "msoPropertyBoolean"
Case "Date"
TypeOfVariableIfNotString = "msoPropertyDate"
Case "Number"
TypeOfVariableIfNotString = "msoPropertyNumber"
Case Else
TypeOfVariableIfNotString = "msoPropertyString"
End Select
With ActiveDocument
If .BuiltInDocumentProperties.Exists(NameofCustomProperty) = True Then
.BuiltInDocumentProperties(NameofCustomProperty).Value =
ValueofCustomProperty
Else
.CustomDocumentProperties.Add _
Name:=NameofCustomProperty, LinkToContent:=False,
Value:=ValueofCustomProperty, Type:=TypeOfVariableIfNotString
End If
End With

Obviously, if I can save these in properties of the activedocument, then I
will be 90% of the way home.
 
D

Doug Robbins - Word MVP

You could create document variables in the document.

ActiveDocument.Variables("variableName").Value = [something supplied by
Access"

Then you can display the content of the variable in a { DOCVARIABLE
variableName } field

or retrieve at any time by the use of

Dim strAccessValue as String (or whatever type of thing it is)

strAccessValue = ActiveDocument.Variables("variableName").Value

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
C

Chirag

LA Lawyer said:
The latter: I am starting Word through Access VBA and then I want to use
those values in Word throughout the session, even if I left the
ActiveDocument.

After starting Word, your code in Word can perhaps automate your already
open instance of Access and ask it for the data you want through the
Application.Run() method of Access.

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
F

Fumei2 via OfficeKB.com

1. setting them as DOCVARIABLES will work for each document, but not for ANY
document.

2. if you want the variables toi be accessible to Word, while you are action
Word FROM Access, then you can simply use them as Public variables in Access.
However, if I understand correctly, you want to set a variable value, from
Access, and then be able to open Word and have those variables accessible...
even if you close Access. Correct?

In other words, you are using Access to see a value to a variable, but you
are NOT dependent on Access for getting those values (after they are set).

In which case, I am with the idea of setting the values in an INI file. Word
can read the INI file. They can be used by any document, not just
activedocument.
[quoted text clipped - 6 lines]
those values in Word throughout the session, even if I left the
ActiveDocument.

After starting Word, your code in Word can perhaps automate your already
open instance of Access and ask it for the data you want through the
Application.Run() method of Access.

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 

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