View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default vba code to send a filename to word without starting a new session

Hello,

I got pretty far with my vba project but got stuck now.

What I have so far:
I have 2 monitors, on the left an excel sheet with filenames and on
the right Word running. When I click on a cell with a filename a Word
session is started with the file opened.

The issue:
Each cell click results in a new Word session being started.

What Im looking for:
Vba code to tell a running Word session to display the file selected
in question (and not open a new Word session) The point being is that
Word can be sized to best fit the right monitor and stay that way
while different files are selected from excel and viewed in Word.

Probably some sort of DDE call needed but cant figure out how. In
the near future Id like this to work for powerpoint, IE and
pdf-readers as well. Windows 7 and office 2010.

Maybe there is a generic document viewer which has the option €śallow
only one instance€ť which would solve the issue as well.


Word was designed that way. It always will open another doc in a new
'instance'. If you only need 1 doc open at a time you could close each
doc before opening another. This would require you start an instance of
Word from Excel, then use that 1 instance for all files. Optionally,
you could start an instance and set it up as desired, then grab a fully
qualified ref to it.

Generally speaking, it's not considered 'best practice' to hijack a
running instance of any app that supports multiple instances. That more
or less means if your Excel (or any other) VBA project needs to use
another app then you should create your own instance of that app...

Dim appWD As Object
Set appWD = CreateObject("Word.Application")

...and don't forget to release its mem space when done with it!

Set appWD = Nothing


If you manually start Word specifically for your Excel project's use
you can establish a link to it...

Dim appWD As Object

'Grab running instance
Set appWD = GetObject("Word.Application")
'If not running, start your own instance
If appWD Is Nothing Then Set appWD = CreateObject("Word.Application")

With appWD
'do stuff...
End With 'appWD

Set appWD = Nothing

FWIW
I've been authoring userguides, tech/instruction manuals, product user
manuals, statistical reports, slideshows, and ebooks in Excel since
v2000. I don't use Word much because I haven't found anything it can do
that can't be done in Excel equally as well or better.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus