Opening word documents with a macro

rmcbreen

New Member
Joined
Oct 22, 2002
Messages
26
I am tring to link a workbook to a word document. Basically I want to run a Macro that will open the word document and print it. When I try to record the macro, I get an error that says *.doc files are not supported by excel. Any thoughts?

Thanks

Ryan
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Anne Troy

MrExcel MVP
Joined
Feb 18, 2002
Messages
2,607
You need to first call the Word application because you can't open a Word doc from Excel.

Try this that I stole from somewhere else:

First set a reference to the Word 8.0-object (it's somewhere in tools).
Then use this code:

dim x as new word.application
dim y as new word.document

set y=x.documents.open ("docum.doc")

instead of docum.doc use the name of your word-document including the path.
This way the worddocument is loaded into memory. To make it visisble type:

y.visible=true
 

Jack in the UK

Well-known Member
Joined
Feb 16, 2002
Messages
3,215
Hi

Not quite wat you ask but gives the syntax to create a word session - this code will send data over to work, which might be larger part of whnat you want, also some code in WORD from VBA Excel to give idea of controlling Word from Excel enviroment

Hope this gets you started,

Jack
 

Jack in the UK

Well-known Member
Joined
Feb 16, 2002
Messages
3,215
Ok Oppps forget this bit, kinda important as well

Sub Excel_to_Word_JackintheUK()

Range("A1:A20").Select
Selection.Copy

Set Word6 = CreateObject("Word.Basic")
With Word6
If UCase(Left(Application.OperatingSystem, 3)) <> "MAC" Then
.AppRestore
.AppMaximize 1
Else
AppActivate "Microsoft Word"
End If
.FileNewDefault
'.InsertPara
.Insert "Jack - Test from Excel"
.startofline 15
' .Bold
' .CenterPara
'.startofline 15
Selection.PasteSpecial Paste:=xlValues, operation:=xlNone, _
skipblanks:=False, Transpose:=False
Application.CutCopyMode = False

End With



End Sub
 

Tom Morales

Board Regular
Joined
Feb 16, 2002
Messages
91
Elaborating a bit on Dreamboat's guidance, you include your Word object library from your VB Editor page, Tools/References.

The only pitfall could be if you give the code to others to use, and their references aren't properly set up. In that event, you'll get to learn about AddFromFile and AddFromGuid nethods so that your code automatically adds the needed references.
Tom

_________________
This message was edited by Tom Morales on 2002-10-26 11:01
 

rmcbreen

New Member
Joined
Oct 22, 2002
Messages
26
Thanks for all of the help, I just got a chance to look at your advice, and am going to try to get everything to work out before I leave work.

Thanks again.

Ryan
 

Forum statistics

Threads
1,144,329
Messages
5,723,734
Members
422,512
Latest member
MHau5

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top