473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Shell to Word and load a specific document

Is there a way to shell to Microsoft Word from Access and load a specific
template - using VBA?

dixie
Aug 16 '06 #1
12 10616

Dixie wrote:
Is there a way to shell to Microsoft Word from Access and load a specific
template - using VBA?

dixie
Like this:
http://www.mvps.org/access/modules/mdl0043.htm

Aug 16 '06 #2
Or, you could use the simple Shell command

Call Shell("C:\program files\Microsoft Office\Office11\winword.exe
h:\templates\templatetest.dot", 1)

Just change the pathname to suit.

Dixie wrote:
Is there a way to shell to Microsoft Word from Access and load a specific
template - using VBA?

dixie
Aug 16 '06 #3
or possibly

Application.followhyperlink "h:\templates\templatetest.dot"

Aug 16 '06 #4
I am using a template called "Rewards letter.dot".

When I use thecfollowing code:

Call Shell("C:\program files\Microsoft Office\Office\winword.exe
f:\templates\(Rewards Letter.dot)", 1)

Word opens and then says "The file rewards.doc is not available."
How do I handle the two word template name? Is there some way of doing it
with different quotation marks?

dixie
"Tanis" <dn*****@accuride.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
Or, you could use the simple Shell command

Call Shell("C:\program files\Microsoft Office\Office11\winword.exe
h:\templates\templatetest.dot", 1)

Just change the pathname to suit.

Dixie wrote:
>Is there a way to shell to Microsoft Word from Access and load a specific
template - using VBA?

dixie

Aug 16 '06 #5
"Dixie" <di***@dogmail.comwrote in
news:12*************@corp.supernews.com:
I am using a template called "Rewards letter.dot".

When I use thecfollowing code:

Call Shell("C:\program files\Microsoft
Office\Office\winword.exe f:\templates\(Rewards Letter.dot)",
1)

Word opens and then says "The file rewards.doc is not
available." How do I handle the two word template name? Is
there some way of doing it with different quotation marks?

dixie
Yes.

what you want in the command is "C:\program files\Microsoft
Office\Office\winword.exe" "f:\templates\Rewards Letter.dot"

To get that, you
Call Shell("""C:\program files\Microsoft Office\Office
\winword.exe""
""f:\templates\Rewards Letter.dot""", 1)

The rule is to use two doublequotes to embed one doublequote in
the string. Then quote the entire string as usual.

"Tanis" <dn*****@accuride.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
>Or, you could use the simple Shell command

Call Shell("C:\program files\Microsoft
Office\Office11\winword.exe h:\templates\templatetest.dot",
1)

Just change the pathname to suit.

Dixie wrote:
>>Is there a way to shell to Microsoft Word from Access and
load a specific template - using VBA?

dixie




--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 16 '06 #6
I haven't seen this one before, but it works. The problem I see is that the
window that I am running the Access application in mimimises to the task bar
as soon as Word opens, then when I close word, it does not return to that
window automatically. If there was a way or getting the active Access
window back when you closed the Word document, this would be good.

dixie

"Ron2006" <ro******@hotmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
or possibly

Application.followhyperlink "h:\templates\templatetest.dot"

Aug 16 '06 #7
OK, that works fine. Now, I need to make this generic. I need to
substitute some DLookups for the path to Word and for the path to the
template. I have used this sort of stuff before, but not in the Call Shell
context.

This is sort of what I am looking to do:

Call Shell("DLookup("[LetterLabel]", "tblSetup", "ControlID=152") &" " &
CurrentProject.Path & "\Templates\" & DLookup("[Letter]", "tblLetters",
"ControlID=49") & ".dot")", 1)

Needless to say, it is not working and I get an Expected list separator or )
error. Again, I feel this should work, but I am tangled in quotations
again.

The DLookup on tblSetup returns the full path to winword.exe and the DLookup
on tblLetters gives me the basic letter template name without the .dot
extension which is added in the code line.

Please?

dixie

"Bob Quintal" <rq******@sPAmpatico.cawrote in message
news:Xn**********************@66.150.105.47...
"Dixie" <di***@dogmail.comwrote in
news:12*************@corp.supernews.com:
>I am using a template called "Rewards letter.dot".

When I use thecfollowing code:

Call Shell("C:\program files\Microsoft
Office\Office\winword.exe f:\templates\(Rewards Letter.dot)",
1)

Word opens and then says "The file rewards.doc is not
available." How do I handle the two word template name? Is
there some way of doing it with different quotation marks?

dixie

Yes.

what you want in the command is "C:\program files\Microsoft
Office\Office\winword.exe" "f:\templates\Rewards Letter.dot"

To get that, you
Call Shell("""C:\program files\Microsoft Office\Office
\winword.exe""
""f:\templates\Rewards Letter.dot""", 1)

The rule is to use two doublequotes to embed one doublequote in
the string. Then quote the entire string as usual.

>"Tanis" <dn*****@accuride.comwrote in message
news:11*********************@b28g2000cwb.googlegr oups.com...
>>Or, you could use the simple Shell command

Call Shell("C:\program files\Microsoft
Office\Office11\winword.exe h:\templates\templatetest.dot",
1)

Just change the pathname to suit.

Dixie wrote:
Is there a way to shell to Microsoft Word from Access and
load a specific template - using VBA?

dixie



--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 16 '06 #8
"Dixie" <di***@dogmail.comwrote in
news:12*************@corp.supernews.com:
OK, that works fine. Now, I need to make this generic. I
need to substitute some DLookups for the path to Word and for
the path to the template. I have used this sort of stuff
before, but not in the Call Shell context.

This is sort of what I am looking to do:

Call Shell("DLookup("[LetterLabel]", "tblSetup",
"ControlID=152") &" " & CurrentProject.Path & "\Templates\" &
DLookup("[Letter]", "tblLetters", "ControlID=49") & ".dot")",
1)

Needless to say, it is not working and I get an Expected list
separator or ) error. Again, I feel this should work, but I
am tangled in quotations again.

The DLookup on tblSetup returns the full path to winword.exe
and the DLookup on tblLetters gives me the basic letter
template name without the .dot extension which is added in the
code line.

Please?
Divide and conquer!

The first thing to do is move the dlookups to variables. Then
examine the contents of those variables after they have been
set. Also move the multiple quotes to a symbolic constant.

Dim filePath as string, filename as string
Const dQt as string = """"

filepath = DLookup("[LetterLabel]", "tblSetup", "ControlID=152")
filename = DLookup("[Letter]", "tblLetters", "ControlID=49")

debug.print filepath, filename

'the resulting code is a lot easier to debug.
call shell(dQt & filepath & dQt _
& " " & dQt & filename & ".dot" & dQt _
& ")", 1)
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 17 '06 #9
Call Shell(DLookup("[LetterLabel]", "tblSetup", "ControlID=152") & " " &
CurrentProject.Path & "\Templates\" & DLookup("[Letter]", "tblLetters",
"ControlID=49") & ".dot", 1)

I've just discovered that the above code works perfectly correctly if the
template name in the Letter field of tblLetters is only one word. If there
is a space in it, then it doesn't work. So the problem with the above code
is that the 2nd DLookup returns a space in the name of the template and it
can't work. That suggests to me some extra inverted commas for the second
DLookup only, but I can't seem to work out how to do it.

I have also noticed that if I put inverted commas around the actuall
template name in tblLetters such that it is "Commendation Letter" in the
table, it works fine. I don't really want to do it that way however if I
can solve it with some inverted commas in the code.

dixie

"Dixie" <di***@dogmail.comwrote in message
news:12*************@corp.supernews.com...
OK, that works fine. Now, I need to make this generic. I need to
substitute some DLookups for the path to Word and for the path to the
template. I have used this sort of stuff before, but not in the Call
Shell context.

This is sort of what I am looking to do:

Call Shell("DLookup("[LetterLabel]", "tblSetup", "ControlID=152") &" " &
CurrentProject.Path & "\Templates\" & DLookup("[Letter]", "tblLetters",
"ControlID=49") & ".dot")", 1)

Needless to say, it is not working and I get an Expected list separator
or ) error. Again, I feel this should work, but I am tangled in
quotations again.

The DLookup on tblSetup returns the full path to winword.exe and the
DLookup on tblLetters gives me the basic letter template name without the
.dot extension which is added in the code line.

Please?

dixie

"Bob Quintal" <rq******@sPAmpatico.cawrote in message
news:Xn**********************@66.150.105.47...
>"Dixie" <di***@dogmail.comwrote in
news:12*************@corp.supernews.com:
>>I am using a template called "Rewards letter.dot".

When I use thecfollowing code:

Call Shell("C:\program files\Microsoft
Office\Office\winword.exe f:\templates\(Rewards Letter.dot)",
1)

Word opens and then says "The file rewards.doc is not
available." How do I handle the two word template name? Is
there some way of doing it with different quotation marks?

dixie

Yes.

what you want in the command is "C:\program files\Microsoft
Office\Office\winword.exe" "f:\templates\Rewards Letter.dot"

To get that, you
Call Shell("""C:\program files\Microsoft Office\Office
\winword.exe""
""f:\templates\Rewards Letter.dot""", 1)

The rule is to use two doublequotes to embed one doublequote in
the string. Then quote the entire string as usual.

>>"Tanis" <dn*****@accuride.comwrote in message
news:11*********************@b28g2000cwb.googleg roups.com...
Or, you could use the simple Shell command

Call Shell("C:\program files\Microsoft
Office\Office11\winword.exe h:\templates\templatetest.dot",
1)

Just change the pathname to suit.

Dixie wrote:
Is there a way to shell to Microsoft Word from Access and
load a specific template - using VBA?
>
dixie


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com


Aug 17 '06 #10
"Dixie" <di***@dogmail.comwrote in
news:12*************@corp.supernews.com:
I haven't seen this one before, but it works. The problem I see
is that the window that I am running the Access application in
mimimises to the task bar as soon as Word opens, then when I close
word, it does not return to that window automatically. If there
was a way or getting the active Access window back when you closed
the Word document, this would be good.
Look up ShellAndWait on mvps.org/access.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Aug 17 '06 #11
You've dropped your embedded double quotes again.

It should be

Call Shell(DLookup("[LetterLabel]", "tblSetup", "ControlID=152") & " """ &
CurrentProject.Path & "\Templates\" & DLookup("[Letter]", "tblLetters",
"ControlID=49") & ".dot""", 1)

or if you look at Bob Quintal's post where he starts with the words "Divide
and conquer!", he illustrates the way a programmer would approach this in
order to break the problem down into manageable bits.

--

Terry Kreft
"Dixie" <di***@dogmail.comwrote in message
news:12*************@corp.supernews.com...
Call Shell(DLookup("[LetterLabel]", "tblSetup", "ControlID=152") & " " &
CurrentProject.Path & "\Templates\" & DLookup("[Letter]", "tblLetters",
"ControlID=49") & ".dot", 1)

I've just discovered that the above code works perfectly correctly if the
template name in the Letter field of tblLetters is only one word. If
there
is a space in it, then it doesn't work. So the problem with the above
code
is that the 2nd DLookup returns a space in the name of the template and it
can't work. That suggests to me some extra inverted commas for the second
DLookup only, but I can't seem to work out how to do it.

I have also noticed that if I put inverted commas around the actuall
template name in tblLetters such that it is "Commendation Letter" in the
table, it works fine. I don't really want to do it that way however if I
can solve it with some inverted commas in the code.

dixie

"Dixie" <di***@dogmail.comwrote in message
news:12*************@corp.supernews.com...
OK, that works fine. Now, I need to make this generic. I need to
substitute some DLookups for the path to Word and for the path to the
template. I have used this sort of stuff before, but not in the Call
Shell context.

This is sort of what I am looking to do:

Call Shell("DLookup("[LetterLabel]", "tblSetup", "ControlID=152") &" " &
CurrentProject.Path & "\Templates\" & DLookup("[Letter]", "tblLetters",
"ControlID=49") & ".dot")", 1)

Needless to say, it is not working and I get an Expected list separator
or ) error. Again, I feel this should work, but I am tangled in
quotations again.

The DLookup on tblSetup returns the full path to winword.exe and the
DLookup on tblLetters gives me the basic letter template name without
the
.dot extension which is added in the code line.

Please?

dixie

"Bob Quintal" <rq******@sPAmpatico.cawrote in message
news:Xn**********************@66.150.105.47...
"Dixie" <di***@dogmail.comwrote in
news:12*************@corp.supernews.com:

I am using a template called "Rewards letter.dot".

When I use thecfollowing code:

Call Shell("C:\program files\Microsoft
Office\Office\winword.exe f:\templates\(Rewards Letter.dot)",
1)

Word opens and then says "The file rewards.doc is not
available." How do I handle the two word template name? Is
there some way of doing it with different quotation marks?

dixie

Yes.

what you want in the command is "C:\program files\Microsoft
Office\Office\winword.exe" "f:\templates\Rewards Letter.dot"

To get that, you
Call Shell("""C:\program files\Microsoft Office\Office
\winword.exe""
""f:\templates\Rewards Letter.dot""", 1)

The rule is to use two doublequotes to embed one doublequote in
the string. Then quote the entire string as usual.
"Tanis" <dn*****@accuride.comwrote in message
news:11*********************@b28g2000cwb.googlegr oups.com...
Or, you could use the simple Shell command

Call Shell("C:\program files\Microsoft
Office\Office11\winword.exe h:\templates\templatetest.dot",
1)

Just change the pathname to suit.

Dixie wrote:
Is there a way to shell to Microsoft Word from Access and
load a specific template - using VBA?

dixie



--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com


Aug 17 '06 #12
I actually used Bob Quintal's approach. It returned the correct filepath
and filename in the Immediate window, but it the entire expression still did
not locate the file when opening Word. It was giving an error message "The
file Commendation Letter.dot) is not available" (in other words, it was
appending the parenthesis onto the filename.) I already knew I had a
problem with quotation marks in the second DLookup and was working on that
yesterday before I had to go out.

Thankyou everyone who has helped me. The last expression from Terry was
what I was looking for and I DO know I need to brush up on my use of
multiple quotation marks in such expressions. My problem is they crop up so
infrequently.

dixie

"Terry Kreft" <te*********@mps.co.ukwrote in message
news:Xt******************************@eclipse.net. uk...
You've dropped your embedded double quotes again.

It should be

Call Shell(DLookup("[LetterLabel]", "tblSetup", "ControlID=152") & " """ &
CurrentProject.Path & "\Templates\" & DLookup("[Letter]", "tblLetters",
"ControlID=49") & ".dot""", 1)

or if you look at Bob Quintal's post where he starts with the words
"Divide
and conquer!", he illustrates the way a programmer would approach this in
order to break the problem down into manageable bits.

--

Terry Kreft
"Dixie" <di***@dogmail.comwrote in message
news:12*************@corp.supernews.com...
>Call Shell(DLookup("[LetterLabel]", "tblSetup", "ControlID=152") & " " &
CurrentProject.Path & "\Templates\" & DLookup("[Letter]", "tblLetters",
"ControlID=49") & ".dot", 1)

I've just discovered that the above code works perfectly correctly if the
template name in the Letter field of tblLetters is only one word. If
there
>is a space in it, then it doesn't work. So the problem with the above
code
>is that the 2nd DLookup returns a space in the name of the template and
it
can't work. That suggests to me some extra inverted commas for the
second
DLookup only, but I can't seem to work out how to do it.

I have also noticed that if I put inverted commas around the actuall
template name in tblLetters such that it is "Commendation Letter" in the
table, it works fine. I don't really want to do it that way however if I
can solve it with some inverted commas in the code.

dixie

"Dixie" <di***@dogmail.comwrote in message
news:12*************@corp.supernews.com...
OK, that works fine. Now, I need to make this generic. I need to
substitute some DLookups for the path to Word and for the path to the
template. I have used this sort of stuff before, but not in the Call
Shell context.

This is sort of what I am looking to do:

Call Shell("DLookup("[LetterLabel]", "tblSetup", "ControlID=152") &" "
&
CurrentProject.Path & "\Templates\" & DLookup("[Letter]", "tblLetters",
"ControlID=49") & ".dot")", 1)

Needless to say, it is not working and I get an Expected list separator
or ) error. Again, I feel this should work, but I am tangled in
quotations again.

The DLookup on tblSetup returns the full path to winword.exe and the
DLookup on tblLetters gives me the basic letter template name without
the
.dot extension which is added in the code line.

Please?

dixie

"Bob Quintal" <rq******@sPAmpatico.cawrote in message
news:Xn**********************@66.150.105.47...
"Dixie" <di***@dogmail.comwrote in
news:12*************@corp.supernews.com:

I am using a template called "Rewards letter.dot".

When I use thecfollowing code:

Call Shell("C:\program files\Microsoft
Office\Office\winword.exe f:\templates\(Rewards Letter.dot)",
1)

Word opens and then says "The file rewards.doc is not
available." How do I handle the two word template name? Is
there some way of doing it with different quotation marks?

dixie

Yes.

what you want in the command is "C:\program files\Microsoft
Office\Office\winword.exe" "f:\templates\Rewards Letter.dot"

To get that, you
Call Shell("""C:\program files\Microsoft Office\Office
\winword.exe""
""f:\templates\Rewards Letter.dot""", 1)

The rule is to use two doublequotes to embed one doublequote in
the string. Then quote the entire string as usual.
"Tanis" <dn*****@accuride.comwrote in message
news:11*********************@b28g2000cwb.googleg roups.com...
Or, you could use the simple Shell command

Call Shell("C:\program files\Microsoft
Office\Office11\winword.exe h:\templates\templatetest.dot",
1)

Just change the pathname to suit.

Dixie wrote:
Is there a way to shell to Microsoft Word from Access and
load a specific template - using VBA?
>
dixie



--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com



Aug 17 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jeff Harbin | last post by:
I've got an ACCESS 2000 application that I'm developing. One of the outputs of this app will be to generate a series of 'jobs' which corresponds to a record in the database. Each record will be...
3
by: Bob | last post by:
What I want to do is write a program that reads through a Word Document, finds certain words or sentences I want, and then paste into an Excel spreadsheet. I dont know much about C#. But I...
1
by: Fei Yuan | last post by:
Please forgive me re-posting this question since I wasn't clear in my original post. --------> Starting an external process needs to pass it a ProcessStartInfo() object. ProcessStartInfo has a...
2
by: KnotKnormal | last post by:
I would like to dynamically load a HTML page (or a Word document), which is embedded in a table when the user clicks on a hyperlink to go from HTML page one to HTML page two. For example, I would...
7
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the...
0
by: funeeldy | last post by:
I need to locate a particular table in a document. I cannot hardcode the table number since it could be different in every doc. I do have some header text that comes right before it consistently,...
8
by: Mike | last post by:
Am trying to open a Microsoft Word .doc file using Access 2000 with Shell function (on Windows XP Operating system) Here is the code : Shell "C:\Program Files\Microsoft...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
0
by: ppardi | last post by:
I'm developing an addin for Word 2007 and I need to determine whether a user saves a Word 2007 document in an older format (97-2003) after a save as is done. The scenario is that the user starts...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.