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