Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Pass variable from ThisDocument to Form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kev - 21 Aug 2006 09:01 GMT
My apologies if this is an obvious question, but it's late at night and

my brain is descending into numbness.

I have a word 2003 macro coded into the ThisDocument module of the
template
so that it auto executes on opening the document.

Part of this macro defines a variable called docname which equals the
path name to a pdf file.

I then open up a form (Userform1).  I need to put a button on this form

which will open the pdf file listed in the docname variable.

I've read a few post on public variables and tried to implement, but
cant get my head around the explanations.

Can someone please explain how I access the contents of the docname
variable from my form?

Cheers

Kevin
Western Australia
Cindy M. - 21 Aug 2006 10:43 GMT
Hi Kev,

You say you assign the name to a variable: a document variable
(Documents.Variables) or a variable in your code? I'm going to assume the
latter, but did have to ask...

At the top of the ThisDocument module type:

Public docname as String

Remove the declaration (Dim) of docname in the macro (Document_Open, I
assume).

Now the code behind the form should be able to "talk to" docname.

> My apologies if this is an obvious question, but it's late at night and
>  
[quoted text clipped - 20 lines]
> Can someone please explain how I access the contents of the docname
> variable from my form?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Kev - 22 Aug 2006 07:26 GMT
Hi Cindy, thanks for your post.

Im still having issues and thought I would paste my code here.

This is the code from ThisDocument module of the Word doc:
===================
Public docname As String

Public Sub Document_Open()
docname = "C:\Documents and Settings\Administrator\My Documents\my.pdf"
UserForm1.Show

End Sub
====================

On Userform1 I have a single button.  Here is the code:
====================
Public Sub CommandButton1_Click()
Call Shell("""C:\Program Files\Adobe\Acrobat 7.0\Reader\acrord32.exe""
" & docname, 1)

End Sub
====================

Acrobat Reader opens, but does not open my.pdf (as defined in the
docname variable).
If I hard code the pdf file path, it does open.
I also tried msgbox docname just before the call statement, and it
showed nothing in docname.

What is it that I'm missing (blonde hair tint on standby!)

Cheers

Kevin
Kodeworks - 22 Aug 2006 13:47 GMT
Kevin

There are a two things you need to fix in Command1_Click.

1.  Correctly reference the 'docname' property that you've declared in
ThisDocument.
It should be 'ThisDocument.docname'.  A public variable in declared in
an object must be referred to as a property of that object from outside
that object.  (Sorry, I can't make it  any more clear than that - it's
late for me too :) )

2.  You need to surround 'docname' in the Shell command string with
double quotes as you have already done with the path to the acrobat
reader executable.  Also, take note of the single space character to
separate the executable and file name strings.

Public Sub CommandButton1_Click()
Call Shell("""C:\Program Files\Adobe\Acrobat 7.0\Reader\acrord32.exe""
& _
              " " & """" &  ThisDocument.docname & """", 1)
End Sub

Sunil Jadwani
Kodeworks - Business Automation Solutions
www.kodeworks.com

> Hi Cindy, thanks for your post.
>
[quoted text clipped - 31 lines]
>
> Kevin
Kev - 23 Aug 2006 05:17 GMT
Thankyou so much Cindy and Sunil

Working perfectly now :D
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.